Why does TweetSharp always return only 100 followe

2019-05-21 04:18发布

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?

1条回答
甜甜的少女心
2楼-- · 2019-05-21 05:00

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

查看更多
登录 后发表回答