Twitter API: Get Followers +99

2019-03-16 06:21发布

Using the twitter API (and OAuth) if i was to call for the user followers, (statuses/followers) i would be returned only 99 results.

Is there a way i can return 99, then call again starting at follower 100 then looping through this style of calling until the total number of followers has been returned?

Or just return ALL followers?

7条回答
小情绪 Triste *
2楼-- · 2019-03-16 06:31

Be sure you're using the right call. followers/ids gives you 5000 at a time (but it's just a list of ids). This call, too, uses the cursor to let you step through pages of users. You get a zero back when you have them all.

查看更多
戒情不戒烟
3楼-- · 2019-03-16 06:31

Twitter API restricts us to make api Call for method followers/ids is 15 requests per 15 minutes. If you make more than this api will give you an error message that Rate Limit Reached.

For more information of twitter API rate Limit Visit-https://dev.twitter.com/docs/rate-limiting/1.1 and https://dev.twitter.com/docs/rate-limiting/1.1/limits

查看更多
Root(大扎)
4楼-- · 2019-03-16 06:31
$cursor = -1;
$account_from = 'twitter_account';
do
{
    $json = file_get_contents('http://api.twitter.com/1/statuses/followers/' . $account_from .'json?cursor=' . $cursor);
    $accounts = json_decode($json);
    foreach ($accounts->users as $account)
    {

            array(
                ':twitter_id' => $account->id_str,
                ':account' => $account->screen_name,
                ':description' => $account->description,
            );
    }
    $cursor = $accounts->next_cursor;

}
while ($cursor > 0);
查看更多
走好不送
5楼-- · 2019-03-16 06:32

You need to specify cursor parameter as described in the API documrnation. E.g. specify cursor=-1 to request the first page and then use a next_cursor value returned in the first response:

  http://twitter.com/statuses/followers/barackobama.xml?cursor=-1
  http://twitter.com/statuses/followers/barackobama.xml?cursor=1300794057949944903
查看更多
劫难
6楼-- · 2019-03-16 06:45
<?php
$trends_url = "http://api.twitter.com/1/statuses/followers/fawadghafoor.json";
$ch       = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $trends_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curlout  = curl_exec($ch);
curl_close($ch);
$response = json_decode($curlout, true);

foreach($response as $friends){
      $thumb = $friends['profile_image_url'];
      $url   = $friends['screen_name'];
      $name  = $friends['name'];
?>                         
<a title="<?php echo $name;?>" href="http://www.twitter.com/<?php echo $url;?>"><img class="photo-img" src="<?php echo $thumb?>" border="0" alt="" width="40" /></a>
    <?php  }  ?>
查看更多
倾城 Initia
7楼-- · 2019-03-16 06:46

Twitter only allows a certain number of API requests per hour, and I think minute. You might not be able to retrieve any more than 99 requests at once.

查看更多
登录 后发表回答