Twitter follower count number

后端 未结 4 1613
伪装坚强ぢ
伪装坚强ぢ 2021-02-08 03:44

Is the only way to get the follower count number in plain text is using cURL? or does the twitter API provides any such option?

相关标签:
4条回答
  • 2021-02-08 04:33

    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:

    <?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;
    ?>
    
    0 讨论(0)
  • 2021-02-08 04:36

    https://api.twitter.com/1/users/lookup.json?screen_name=tvdw (my profile, just replace the screen name)

    Also available as XML: https://api.twitter.com/1/users/lookup.xml?screen_name=tvdw

    Obtaining it in PHP:

    $data = json_decode(file_get_contents('https://api.twitter.com/1/users/lookup.json?screen_name=tvdw'), true);
    echo $data[0]['followers_count'];
    
    0 讨论(0)
  • 2021-02-08 04:36

    In API version 1.1 you can use: https://dev.twitter.com/docs/api/1.1/get/users/show

    the 'followers_count' field should contain the follower count number.

    In API version 1 which is deprecated you can use: https://dev.twitter.com/docs/api/1/get/users/show

    0 讨论(0)
  • 2021-02-08 04:41
    <a href="https://twitter.com/twitterapi" class="twitter-follow-button" data-show-count="false" data-lang="en">Follow @twitterapi</a>
    
    <script>
    !function(d,s,id){
        var js,fjs=d.getElementsByTagName(s)[0];
        if(!d.getElementById(id)){
            js=d.createElement(s);
            js.id=id;
            js.src="//platform.twitter.com/widgets.js";
            fjs.parentNode.insertBefore(js,fjs);
        }
    }
    (document,"script","twitter-wjs");    
    </script>
    

    data-show-count = "true"

    0 讨论(0)
提交回复
热议问题