加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何使用PHP在Twitter中发布

发布时间:2020-12-13 17:29:31 所属栏目:PHP教程 来源:网络整理
导读:我的网站如何在Twitter上发短信?我正在使用 PHP脚本.无论从我的网站发送什么推文,都应该更新我的微博帐号.我使用以下代码,但是在我的twitter帐户中没有更新: // Set username and password$username='myusername';$password='*********';// The message yo
我的网站如何在Twitter上发短信?我正在使用 PHP脚本.无论从我的网站发送什么推文,都应该更新我的微博帐号.我使用以下代码,但是在我的twitter帐户中没有更新:
// Set username and password
$username='myusername';
$password='*********';
// The message you want to send
$message = 'Nice to c all again.Have a nice day..';
// 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,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle,CURLOPT_POST,CURLOPT_POSTFIELDS,"status=".$message);
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 'Try again';
} else {
    echo 'success';
}

这个脚本正在返回一个成功的消息,但是当我查看我的Twitter账号时,没有发现任何tweets.

可能是什么问题呢?

您正在使用基本身份验证(用户名和密码)发送推文.这不再允许.有很多这个在线的例子,但是Twitter在去年8月关闭了它.您现在必须使用OAuth进行身份验证.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读