Php Twitter中的关注者计数

Php Twitter中的关注者计数,php,twitter,twitter-follow,Php,Twitter,Twitter Follow,如何让我的追随者计数与PHP的数字 我在这里找到了这个答案:,但它不起作用,因为API 1.0不再处于活动状态 我也尝试过使用这个URL使用API 1.1:但是它显示了一个错误(错误的身份验证数据) 这是我的密码: $data = json_decode(file_get_contents('http://api.twitter.com/1.1/users/lookup.json?screen_name=google'), true); echo $data[0]['followers_coun

如何让我的追随者计数与PHP的数字

我在这里找到了这个答案:,但它不起作用,因为API 1.0不再处于活动状态

我也尝试过使用这个URL使用API 1.1:但是它显示了一个错误(错误的身份验证数据)

这是我的密码:

$data = json_decode(file_get_contents('http://api.twitter.com/1.1/users/lookup.json?screen_name=google'), true);
echo $data[0]['followers_count'];

Twitter API 1.0已弃用,不再处于活动状态。使用,您需要oAuth身份验证来从Twitter检索数据

改用这个:

<?php 
require_once('TwitterAPIExchange.php'); //get it from https://github.com/J7mbo/twitter-api-php

/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "YOUR_OAUTH_ACCESS_TOKEN",
'oauth_access_token_secret' => "YOUR_OAUTH_ACCESS_TOKEN_SECRET",
'consumer_key' => "YOUR_CONSUMER_KEY",
'consumer_secret' => "YOUR_CONSUMER_SECRET"
);

$ta_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name=REPLACE_ME';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$follow_count=$twitter->setGetfield($getfield)
->buildOauth($ta_url, $requestMethod)
->performRequest();
$data = json_decode($follow_count, true);
$followers_count=$data[0]['user']['followers_count'];
echo $followers_count;
?>

在某些情况下,解析XML可能更容易

这里有一个解决方案(已测试):

<?php 
$xml = new SimpleXMLElement(urlencode(strip_tags('https://twitter.com/users/google.xml')), null, true);
echo "Follower count: ".$xml->followers_count;
?>
followers\u计数;
?>

希望这有帮助

如果不使用auth执行(用您的用户替换“stackoverflow”)

使用php

$tw_username = 'stackoverflow'; 
$data = file_get_contents('https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names='.$tw_username); 
$parsed =  json_decode($data,true);
$tw_followers =  $parsed[0]['followers_count'];

您现在需要在v1.1中使用oauth连接,我该如何使用它?小的输入错误,替换后缺少一个引用me@Novocaine88:谢谢。修正:)谢谢,但我找到了这个。是否有任何简短的PHP代码来获取追随者编号?它显示了以下错误:(我不能在这里写评论,因为它太长)嗨,上面的代码不起作用。当从json回音时,它什么也没有显示。有什么想法吗?如果你只需要简单的追随者计数/数据,而没有身份验证,这个答案是最好的!杰出的编辑:但不受twitter支持-可能会更改,恕不另行通知。您也可以使用用户id获取信息,例如
https://cdn.syndication.twimg.com/widgets/followbutton/info.json?user_ids=128700677
$tw_username = 'stackoverflow'; 
$data = file_get_contents('https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names='.$tw_username); 
$parsed =  json_decode($data,true);
$tw_followers =  $parsed[0]['followers_count'];