phptwittertwitter-follow

Twitter API not returning all followers


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?


Solution

  • 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