Twitter API not returning all followers

850 views Asked by At

I am using this block of code for getting my followers:

    $trends_url = "http://api.twitter.com/1/statuses/followers/myname.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){ 
       echo $friends['name'];
    }

The problem is, that I can't get the whole list, just 100 followers. Is there any way to get all people which follows me?

4

There are 4 answers

0
Brian On BEST ANSWER

Paging has been implemented using the cursor parameter. Your initial request should look like: http://api.twitter.com/1/statuses/followers/myname.json?curosr=-1

The response will have a parameter containing the value of the next cursor.

Example:

{ ...
  "next_cursor" : 1408398970289681313,
  "next_cursor_str" : "1408398970289681313",
  "previous_cursor" : -1409120171445568880,
  "previous_cursor_str" : "-1409120171445568880"
}

You will need to make additional calls using the cursor identifier returned from each response.

Your next request would look like:

http://api.twitter.com/1/statuses/followers/myname.json?curosr=1408398970289681313

You can also include the count parameter with each request to specify the total records returned.

Twitter API Wiki:

https://dev.twitter.com/docs/api/1/get/statuses/followers

0
bipin On
enter code here $user_id        = $_GET['user_id'];
$screen_name    = $_GET['screen_name'];
$name       = $_GET['searchname'];
$code           = $connection->get('followers/list', array('screen_name' => $screen_name,'user_id' => $user_id));

Blockquote This is usefull for all followers get

0
Lobo On

The twitter API returns pages of 100 items. You must make several requests, as many as want to get user pages.

0
Borniet On

This function of the Twitter API is deprecated. It only returns the first 100 followers that have recently tweeted. Check out this link for more info: Followers Twitter API Info