0
当我的更新字符串中有一个&时,我对Twitter API的自动调用会导致问题。正确地结束编码&for twitter post
在我使用CURL调用Twitter API之前,如何正确编码包含&的更新字符串$update
?
// 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?!';
}
通过不安全的HTTP电线经过您的用户名和密码Twitter是一个真是糟糕的主意。 – 2009-10-15 14:52:37
请给我一个安全的方法,我会用它。 :) – ian 2009-10-15 14:53:57
将“http”更改为“https” – Greg 2009-10-15 14:58:43