如何使用php在twitter上发布消息

时间:2010-12-02 07:22:03

标签: php twitter

我发布msg的以下脚本无效。任何人都可以帮助我吗?

$username = ($_POST['t_user']);
$password = ($_POST['t_pass']);
$message = ($_POST['t_update']);

$url = 'http://twitter.com/statuses/update.xml';
$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);
if (empty($buffer)) {
    echo "<p align=\"center\" >".'Sorry, due to an error your Twitter status could not be updated! Please check your username/password!'."</p>";
} else {
    echo "<p align=\"center\">".'Your Twitter status has successfully been updated!'."</p>";
}

2 个答案:

答案 0 :(得分:3)

您需要切换到OAuth,引用页面:

  

我们在2009年12月宣布了Basic Auth的弃用。它从平台的删除日期定在2010年6月。我们在2010年6月底宣布,我们已将此推迟到2010年8月16日。

答案 1 :(得分:0)

您可以从本教程中获得灵感:

使用oAuth和PHP创建简单的Twitter应用程序
http://www.1stwebdesigner.com/tutorials/twitter-app-oauth-php/