Only Bolivian Here
Only Bolivian Here

Reputation: 36743

Why does TweetSharp always return only 100 followers?

I'm using the TweetSharp library in a .NET 4 (C#) application.

Here is a helper method I built that returns followers for a given user.

public static void FindFollowersForUser(TwitterUserModel twitterUser)
{
                                            //A simple string for screen name.
    var followers = service.ListFollowersOf(twitterUser.TwitterName);
    foreach (var follower in followers)
    {
                   //Followers is a simple List<string>.
        twitterUser.Followers.Add(follower.ScreenName);
    }
}

The code runs fine but using breakpoints I see that even if the user has more than 100 followers (I check on the official site), the object in my application has only 100.

Is there a way to get all of the followers for a twitter user using TweetSharp?

Upvotes: 2

Views: 1934

Answers (1)

yamen
yamen

Reputation: 15618

You need to go through the cursor:

var followers = service.ListFollowersOf(twitterUser.TwitterName, -1);
while (followers.NextCursor != null)
{
    followers =  service.ListFollowersOf(user_id, followers.NextCursor);
    foreach (var follower in followers)
    {
         twitterUser.Followers.Add(follower.ScreenName);
    }
}

You can see this in some of the tests: https://github.com/danielcrenna/tweetsharp/blob/master/src/net40/TweetSharp.Next.Tests/Service/TwitterServiceTests.cs

Upvotes: 7

Related Questions