2010-12-13 90 views
0

喜目前我在我的网站开发的Twitter更新......在这里,我已经写了我的代码..当在API控制台工作IM我不能让APROPER结果..Twitter应用程序API

<?php 


$tweet_text = 'Hello Twitter'; 
print "Posting...\n"; 
$result = post_tweet($tweet_text); 
print "Response code: " . $result . "\n"; 

function post_tweet($tweet_text) { 

    // Use Matt Harris' OAuth library to make the connection 
    // This lives at: https://github.com/themattharris/tmhOAuth 
    require_once('tmhoauth/tmhOAuth.php'); 

    // Set the authorization values 
    // In keeping with the OAuth tradition of maximum confusion, 
    // the names of some of these values are different from the Twitter Dev interface 
    // user_token is called Access Token on the Dev site 
    // user_secret is called Access Token Secret on the Dev site 
    // The values here have asterisks to hide the true contents 
    // You need to use the actual values from Twitter 
    $connection = new tmhOAuth(array(
    'consumer_key' => 'XXX', 
    'consumer_secret' => 'XXX', 
    'user_token'  => 'XXX', 
    'user_secret'  => 'XXX', 
)); 

    // Make the API call 
    $connection->request('POST', 
    $connection->url('1/statuses/update'), 
    array('status' => $tweet_text)); 

    return $connection->response['code']; 
} 
?> 

stsuus响应看起来像它下面

{ 
    "request": "\/1\/statuses\/update.json", 
    "error": "Client must provide a 'status' parameter with a value." 
} 


statuus:403 forbidden 

任何一个可以解释为什么出错?

,请多关照

+1

您可能想要隐藏您的消费者密钥信息 – fire 2010-12-13 11:14:38

回答

1

其实,这是我的代码从我的网站,版权仅归信息已被删除: http://140dev.com/twitter-api-programming-tutorials/hello-twitter-oauth-php/

告诉你这里不能是你正在运行的代码。您的代码仅返回此行的响应代码: return $ connection-> response ['code'];

但是,您的消息显示它将返回响应,如果您的代码是: return $ connection-> response ['response'];

所以你没有显示你正在运行的真实代码。这使得它很难调试。如果$ tweet_text没有值,那么您的错误只能返回该消息。我测试了我的代码,当我使用$ tweet_text的空白版本时,我得到了相同的错误消息。

然后我复制你的代码,并把我的OAuth标记放入它。它没有问题。我只能得出结论,你没有向我们展示你真正运行的代码。没有看到实际的代码,不可能告诉你为什么它不能正常工作。

未来,当您发现带有GPL许可证的代码时,请保留版权和许可证声明。

+0

非常感谢您先生...现在我清楚..我将运行代码... – bharath 2010-12-14 04:56:11

相关问题