我必须将 Twitter 集成到我必须发送推文的应用程序中。我正在使用以下代码,但执行时收到响应代码 401。
如何使用 PHP 向 Twitter 发送推文?
<?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'];
}
?>