【发布时间】:2013-11-05 18:51:03
【问题描述】:
我使用以下函数发布到 twitter,它返回一条成功消息,但该推文没有出现在 twitter 时间线上。请注意,该网站使用 WAMP 在我的本地主机上。 我启用了卷曲。
下面的函数:
function Post_to_twitter($message){
// Set username and password
$username = 'myaccountusername';
$password = 'mypass';
// set the twitter API address
$url = 'http://twitter.com/statuses/update.json';
// setup a curl process
$curl_handle = curl_init();
// set the url of the curl process
curl_setopt($curl_handle, CURLOPT_URL, "$url");
// saves the return value as a string value instead of outputting to browser
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
// to send data as $_POST fields as required by the twitter API
curl_setopt($curl_handle, CURLOPT_POST, 1);
// set the post fields
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
// set the username and password for the connection
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
// exectute the curl request and save output as $buffer variable
$buffer = curl_exec($curl_handle);
// close the curl connection
curl_close($curl_handle);
// decode json output into array
$json_output = json_decode($buffer, true);
$status = '' ;
// check for success or failure
if (isset($json_output['error'])) {
// tweet not successful, display error
$status = 'failed' ;
}
else {
$status = 'succesful' ;
}
return $status ;
}
echo Post_to_twitter('Hello world');
【问题讨论】:
-
有错误吗?此外,如果它是重复的推文,它可能不会显示。