How to get all the followers

Mar 6, 2014 at 6:41 PM
Edited Mar 6, 2014 at 6:55 PM

Using the below code i am able to get 250 followers, and if i try to run the below code in loop to get all the followers then the same followers are coming again, is there any way to get all the followers with entities (idstr, screenname & username) in a single hit or using paging logic i need to get more than 1lac followers, please advice on this. Thanks in advance.

var user = User.GetUserFromScreenName(userName);
var followers = user.GetFollowers();

Will the below code will return all the followers (more than 1 lac) if i pass the token of the particular account
    public static void GetFollowers(IToken token)
        ITokenUser u = new TokenUser(token);

        foreach (var follower in u.Followers)
Mar 6, 2014 at 7:52 PM
Hi there,

This is possible in Tweetinvi 0.9 and very easy to do:
var ladygaga = User.GetUserFromScreenName("ladygaga");
var followers = ladygaga.GetFollowers(2000);
Now I would like you to be very careful with this!
Twitter does not provide a method to retrieve all the followers of a specific user.

To get a list of followers from a User we first need to use a cursored query retrieving a specific number of followers Ids :

Limit : 5000 * 180 = 900 000 ids

When this is done we need to use user lookup to get user informations :

The last one is limited to 180 requests per user connected and every request can get a maximum of 100 users.
Consequently you can get up to 180 x 100 = 18 000 followers with a specific credential.

Please be sure that you need to get all the followers and not all the follower ids. If you need the follower ids then you can get up to 900.000 follower ids.
Also please note that these limits are reset every 15 minutes.

Hope this helps.
Mar 7, 2014 at 4:31 AM
Hi Linvi,

Thanks for your great help, could you please share the sample code for using cursor in Tweetinvi 0.9 it will be helpful for everyone. Thanks again

Mar 7, 2014 at 9:32 AM

Tweetinvi has been developed so you don't ever need to do a query for implemented features. Though if you really want to perform a CursoredQuery for Follower Ids here is the code you need.
TwitterCredentials.SetCredentials("CREDENTIAL", "CREDENTIAL", "CREDENTIAL", "CREDENTIAL");
var userId = 14230524;
var followerQuery = String.Format("{0}", userId);
int maxObjectsToRetrieve = 7500;
var returnedIds = TwitterAccessor.ExecuteCursorGETQuery<IIdsCursorQueryResultDTO>(followerQuery, maxObjectsToRetrieve).SelectMany(x => x.Ids);

// You will now have 10000 Follower Ids and not 7500 because this is returning result of the query itself (2 results of 5000 each)
// You can now limit the size by just taking the first 7500 ones.
var followerIds = returnedIds.Take(maxObjectsToRetrieve);
Marked as answer by sdhakshinamoorthy on 3/7/2014 at 3:23 AM
Mar 7, 2014 at 11:20 AM
Dear Linvi,

Thanks again for your great help, it will be helpful for others also. You are genius, hats off. Will keep in touch for all your updates. Thanks again,

Mar 7, 2014 at 12:48 PM
Hi Linvi,

I am getting "An entry with the same key already exists." if i try to get the next ids using the nextcursor, pfb the code that i tried , please correct me where i am wrong, thanks in advance

var followerQuery = String.Format("{0}&cursor={1}", screenName, "1461847482652938527");
var resultSet = TwitterAccessor.ExecuteCursorGETQuery<IIdsCursorQueryResultDTO>(followerQuery, maxObjectsToRetrieve);
Mar 7, 2014 at 5:04 PM
Edited Mar 7, 2014 at 5:04 PM

When calling ExecuteCursorGETQuery do not specify the cursor in the address, this will be done for you.
If you wish to start from a specific cursor_id then call the method with the extra parameter:
var followerQuery = String.Format("{0}", screenName); 
var resultSet = TwitterAccessor.ExecuteCursorGETQuery<IIdsCursorQueryResultDTO>(followerQuery, maxObjectsToRetrieve, 1461847482652938527);
Hope this helps.
Marked as answer by linvi on 3/18/2014 at 7:27 AM
Mar 7, 2014 at 6:33 PM
Hi linvi,

Thanks for the help, let me check with that.

Mar 9, 2014 at 2:44 PM
Hi linvi,

Its perfectly working. Will update all my previous coding to the latest one (0.9). Thanks again for your great help.