Php 获取Twitter用户数
我在一个网站上继承了这段PHP代码,该网站获得了该帐户的Twitter追随者,但它在错误日志中返回了以下内容:Php 获取Twitter用户数,php,twitter,Php,Twitter,我在一个网站上继承了这段PHP代码,该网站获得了该帐户的Twitter追随者,但它在错误日志中返回了以下内容: PHP Warning: file_get_contents(http://twitter.com/users/show/twitterusername): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found\r 其中“twitterusername”是我的twitter用户名。如果我在浏览器中访问该
PHP Warning: file_get_contents(http://twitter.com/users/show/twitterusername): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found\r
其中“twitterusername”是我的twitter用户名。如果我在浏览器中访问该URL,它确实会返回一个未找到的页面。我怀疑Twitter在某个阶段改变了这里的某些东西;我不知道什么时候导致此失败,此脚本需要更新
有谁能帮我找出需要更改哪些内容才能返回推特计数
提前谢谢。代码如下:
$cache = get_transient('twitterfollowerscount' . $username);
if ($cache) {
$count = get_option('twitterfollowerscount' . $username);
if($count ==0){
$url = 'http://twitter.com/users/show/' . urlencode($username);
$xml=file_get_contents($url);
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
$count = $match[1];
}
set_transient('twitterfollowerscount' . $username, 'true', 60 * 30);
update_option('twitterfollowerscount' . $username, $count);
}
} else {
$url = 'http://twitter.com/users/show/' . urlencode($username);
$xml=file_get_contents($url);
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
$count = $match[1];
}
set_transient('twitterfollowerscount' . $username, 'true', 60 * 30);
update_option('twitterfollowerscount' . $username, $count);
}
return $count;
}
使用twitterapi和followers/list请求获取关注者列表要容易得多
如果Twitter像你现在这样改变URL结构会更好 您应该查看twitterapi并重写PHP代码以适应它。