【问题标题】:Twitter follower count numberTwitter关注者计数
【发布时间】:2011-12-30 19:28:30
【问题描述】:

以纯文本形式获取关注者计数的唯一方法是使用 cURL 吗?还是 twitter API 提供任何此类选项?

【问题讨论】:

    标签: php twitter curl


    【解决方案1】:

    https://api.twitter.com/1/users/lookup.json?screen_name=tvdw(我的个人资料,换网名就好)

    也可作为 XML:https://api.twitter.com/1/users/lookup.xml?screen_name=tvdw

    在 PHP 中获取它:

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

    【讨论】:

    • 我相信最后一行现在应该是echo $data[0]['followers_count'];
    【解决方案2】:

    在 API 版本 1.1 中,您可以使用:https://dev.twitter.com/docs/api/1.1/get/users/show

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

    在已弃用的 API 版本 1 中,您可以使用:https://dev.twitter.com/docs/api/1/get/users/show

    【讨论】:

      【解决方案3】:

      Twitter API 1.0 已弃用且不再有效。使用 REST 1.1 API,您需要 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;
      ?>
      

      【讨论】:

        【解决方案4】:
        <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"

        【讨论】:

          猜你喜欢
          • 2013-07-01
          • 2013-09-10
          • 2013-06-28
          • 2014-05-13
          • 1970-01-01
          • 2021-05-22
          • 2012-07-20
          • 2014-01-06
          • 1970-01-01
          相关资源
          最近更新 更多