0

我想从 twitter 获取状态以显示在我的网站上。

这是代码

<?php

function getTwitterStatus($userid){
$url = "https://api.twitter.com/1/statuses/user_timeline/$userid.xml?
count=1&include_rts=1callback=?";

$xml = simplexml_load_file($url) or die("could not connect");

foreach($xml->status as $status){
$text = $status->text;
}
echo $text;
}

getTwitterStatus("soksovat");

?>

我想从 userid = "soksovat" 获得 1 个状态,但是当我运行上述命令时,会出现两个警告:

  1. 警告:simplexml_load_file(https://api.twitter.com/1/statuses/user_timeline/soksovat.xml?count=1&include_rts=1callback=?)[function.simplexml-load-file]:未能打开流:HTTP请求失败!HTTP/1.0 410 Gone in .......... 第 6 行
  2. 警告:simplexml_load_file() [function.simplexml-load-file]:I/O 警告:无法加载外部实体“ https://api.twitter.com/1/statuses/user_timeline/soksovat.xml?count=1&include_rts= 1回调=?” 在 ........第 6 行计数未连接

任何人都可以帮助解决这个问题吗?几天前我被它困住了。

预先感谢。

4

1 回答 1

1

您必须将旧版本更新Twitter API 1.0Twitter API 1.1.

新推特 API:https ://dev.twitter.com/docs/api/1.1/overview

获取用户时间线:https ://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline

有用的 Twitter API v1.1 类:

https://github.com/J7mbo/twitter-api-php/blob/master/TwitterAPIExchange.php

于 2013-08-15T07:22:05.253 回答