我必須實現Twitter集成到一個應用程序,我必須發送推文。我正在使用下面的代碼,但執行時會得到一個響應代碼401。響應代碼401發生在twitter上通過php代碼
如何使用PHP向推特發送推文?
<?php
$tweet_text = 'Hello Twitter';
print "Posting...\n";
$result = post_tweet($tweet_text);
print "Response code: " . $result . "\n";
function post_tweet($tweet_text) {
require_once('tmhOAuth.php');
$connection = new tmhOAuth(array(
'consumer_key' => 'xxxxxxxxxxxxxxxx',
'consumer_secret' => 'xxxxxxxxxxxxxxxx',
'user_token' => 'xxxxxx-xxx',
'user_secret' => 'xxxxxxxxxxxxxx',
'curl_ssl_verifypeer' => false
));
$connection->request('POST',
$connection->url('1/statuses/update'),
array('status' => $tweet_text));
return $connection->response['code'];
}
?>
不公開您的consumer_key和密鑰 – Sky
您能否更具體地提供您的錯誤 – Sky
響應代碼401發生憑據丟失 – gargankit20