Follower count number in Twitter

前端 未结 2 2086
别那么骄傲
别那么骄傲 2020-12-13 22:00

How to get my followers count number with PHP.

I found this answer here: Twitter follower count number, but it is not working because API 1.0 is no longer active.<

2条回答
  •  萌比男神i
    2020-12-13 22:56

    Twitter API 1.0 is deprecated and is no longer active. With the REST 1.1 API, you need oAuth authentication to retrieve data from Twitter.

    Use this instead:

     "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;
    ?>
    

    Parsing the XML might be easier in some cases.

    Here's a solution (tested):

    followers_count;
    ?>
    

    Hope this helps!

提交回复
热议问题