Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter API: Get Followers +99

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?

like image 923
tarnfeld Avatar asked Dec 06 '09 18:12

tarnfeld


2 Answers

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
like image 174
Eugene Kuleshov Avatar answered Oct 18 '22 09:10

Eugene Kuleshov


<?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  }  ?>
like image 27
Fawad Ghafoor Avatar answered Oct 18 '22 10:10

Fawad Ghafoor