【发布时间】:2010-12-07 01:35:39
【问题描述】:
我使用以下代码将更新发布到 twitter:
// Set username and password for twitter API
$username = '***';
$password = '***';
// 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, 10);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$update");
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 'error?!';
}
else
{
// mark the song as tweetered
mysql_query("UPDATE `songs` SET `tweet` = '1' WHERE `id` = $songid ");
}
}
echo $update;
帖子功能正常,但由于某种原因被切断了。
例如上面的代码会在推特上发布:Tiesto - Feel It In My Bones (Feat. Tegan。
何时发布:Tiesto - Feel It In My Bones (Feat. Tegan & Sara) - 160Kbps http://bit.ly/5mdCK4
我使用 echo $update;最后一行将 twitter 的输出与$update 值进行比较,$update 是正确的。
【问题讨论】: