ian*_*ian 0 php api twitter curl
我使用以下代码将更新发布到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;
Run Code Online (Sandbox Code Playgroud)
然而,由于某种原因,它被切断了.
例如,上面的代码将发布Tiesto - Feel It In My Bones (Feat. Tegan到twitter.
什么时候应该发布: Tiesto - Feel It In My Bones (Feat. Tegan & Sara) - 160Kbps http://bit.ly/5mdCK4
我使用echo $ update; 最后的行比较输出到twitter的$update值并且$update是正确的.
你试过其他输入字符串吗?根据你在那里发布的内容,我敢打赌,你的问题是状态中的&符号,因为这是形式帖子中的元字符.我确信PHP有一些URL编码字符串的功能,你会想要使用它$update.
| 归档时间: |
|
| 查看次数: |
951 次 |
| 最近记录: |