我希望使用TwitterAPIExchange
API获取Twitter中关注计数的总数,但结果不包含以下数据。
我怎么能这样做呢?
followers_count和friends_count是可用的,但不是following_count。
答案 0 :(得分:0)
您可以将以下代码用于关注者计数器:
<?php
require_once('TwitterAPIExchange.php'); //https://github.com/J7mbo/twitter-api-php
/** Access token (https://dev.twitter.com/apps/) **/
$access_token_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"
);
$twitter_api_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name=YOUR SCREEN NAME';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($access_token_settings);
$follow_count=$twitter->setGetfield($getfield)->buildOauth($twitter_api_url, $requestMethod)->performRequest();
$data = json_decode($follow_count, true);
$followers_count=$data[0]['user']['followers_count'];
echo $followers_count;
?>
要将数据解析为xml格式,您可以使用以下代码:
<?php
$xml_data = new SimpleXMLElement(urlencode(strip_tags('https://twitter.com/users/google.xml')), null, true);
echo "Follower count: ".$xml_data->followers_count;
?>
希望这有帮助。