Php 推特关注者计数

Php 推特关注者计数,php,twitter,curl,Php,Twitter,Curl,在纯文本中获取跟随者计数的唯一方法是使用cURL吗?或者twitter API提供了这样的选项吗 (我的个人资料,只需替换屏幕名称) 也可以XML格式提供: 用PHP获取它: $data = json_decode(file_get_contents('https://api.twitter.com/1/users/lookup.json?screen_name=tvdw'), true); echo $data[0]['followers_count']; 在API版本1.1中,您可以使用:

在纯文本中获取跟随者计数的唯一方法是使用cURL吗?或者twitter API提供了这样的选项吗

(我的个人资料,只需替换屏幕名称)

也可以XML格式提供:

用PHP获取它:

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

在API版本1.1中,您可以使用:

“关注者计数”字段应包含关注者计数

在不推荐使用的API版本1中,您可以使用:


!功能(d、s、id){
var js,fjs=d.getElementsByTagName[0];
如果(!d.getElementById(id)){
js=d.createElement;
js.id=id;
js.src=“//platform.twitter.com/widgets.js”;
fjs.parentNode.insertBefore(js,fjs);
}
}
(文件,“脚本”、“推特wjs”);
data show count=“true”

Twitter API 1.0已弃用,不再处于活动状态。使用REST1.1API,您需要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;
?>

我认为最后一行现在应该是
echo$data[0]['followers_count'
<?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;
?>