【发布时间】:2014-01-23 15:10:03
【问题描述】:
如何从我的网站在 Twitter 上发布推文?我正在使用 PHP 脚本。无论我从我的网站发送什么推文,都应该更新我的推特账户。我使用以下代码,但它没有在我的 Twitter 帐户中更新:
// Set username and password
$username='myusername';
$password='*********';
// The message you want to send
$message = 'Nice to c all again.Have a nice day..';
// The twitter API address
$url='http://twitter.com/statuses/update.xml';
// Alternative JSON version
// $url = 'http://twitter.com/statuses/update.json';
// Set up and execute the curl process
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST,1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS,"status=".$message);
curl_setopt($curl_handle, CURLOPT_USERPWD,"$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
// check for success or failure
if (empty($buffer)) {
echo 'Try again';
} else {
echo 'success';
}
此脚本正在返回一条成功消息,但是当我检查我的 Twitter 帐户时,没有找到任何推文。
可能是什么问题?
【问题讨论】:
-
使用诸如“twitter php”之类的关键字的谷歌会抛出大量链接。一些有用的链接是:dev.twitter.com/pages/libraries#phpcode.google.com/p/php-twitter你还没有添加你的脚本。