Friends/ids API Getting all followers


#1

Hello.

i have an issue using this API, let’s assume a user following 10,000 User, Using the friends/ids api allows me to get MAXIMUM 5,000 User, so how can i get the next 5,000 Users ?


#2

You make ’ id_list.txt

function.php;

    <?php
    function getFollowers($screen_name)
    {
            global $connection;
            $followersList = array();
            $cursor = -1;
        
            do{
                $followers = $connection->get('/followers/ids', array('count' => 5000, 'screen_name' => $screen_name, 'cursor' => $cursor));
        								
                if(!isset($followers->errors))
                {
                    $cursor = $followers->next_cursor_str;
        
                    if(is_array($followers->ids))
        			{
                        foreach($followers->ids as $ids)
        				{
        					saveTextFile("id_list.txt","$ids\n");
                        }
                    }
        
                    if(is_null($cursor))
                        $cursor = 0;
        
                    if($connection->http_header["x_rate_limit_remaining"] == 0)
                        break;
                }
                else
                {
                    return $followers->errors;
                }
        
            }while($cursor != 0);
        
            return $followersList;
        }
function saveTextFile($file,$data)
{
	$txtFile = fopen($file,"a");
	
	if($txtFile)
	{
		fwrite($txtFile, $data);
	}
    
    fclose($txtFile); 
}

index.php;

<?php
set_time_limit(0);
require_once('twitteroauth/twitteroauth.php'); // https://github.com/abraham/twitteroauth
require_once('function.php');

$consumer_key = 'xxxxxxxxxxxxxxx';
$consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
$access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$access_token_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';


$connection = new TwitterOAuth($consumer_key, $consumer_secret,$access_token,$access_token_secret);
$aliOS = 'username';
getFollowers($aliOS);

?>

#3

@hmadahorani use the cursor parameter, initialise it to -1 ans send it with other parameters when making a call to the API. within a loop like while(cursor != 0) {}. Inside the loop update the cursor.
Twitter sends a cursor value of 0 if the number of friends of a particular user is or equal to 5000, but it then gives a value if number of friends is more than 5000.