我在 .NET 4.0 WinForms 应用程序中使用 TweetSharp v2.3.0。这对我有用:
// this code assumes that your TwitterService is already properly authenticated
TwitterUser tuSelf = service.GetUserProfile(
new GetUserProfileOptions() { IncludeEntities = false, SkipStatus = false });
ListFollowersOptions options = new ListFollowersOptions();
options.UserId = tuSelf.Id;
options.ScreenName = tuSelf.ScreenName;
options.IncludeUserEntities = true;
options.SkipStatus = false;
options.Cursor = -1;
List<TwitterUser> lstFollowers = new List<TwitterUser>();
TwitterCursorList<TwitterUser> followers = service.ListFollowers(options);
// if the API call did not succeed
if (followers == null)
{
// handle the error
// see service.Response and/or service.Response.Error for details
}
else
{
while (followers.NextCursor != null)
{
//options.Cursor = followers.NextCursor;
//followers = m_twService.ListFollowers(options);
// if the API call did not succeed
if (followers == null)
{
// handle the error
// see service.Response and/or service.Response.Error for details
}
else
{
foreach (TwitterUser user in followers)
{
// do something with the user (I'm adding them to a List)
lstFollowers.Add(user);
}
}
// if there are more followers
if (followers.NextCursor != null &&
followers.NextCursor != 0)
{
// then advance the cursor and load the next page of results
options.Cursor = followers.NextCursor;
followers = service.ListFollowers(options);
}
// otherwise, we're done!
else
break;
}
}
注意:这可能被视为重复问题。(请参阅此处和此处。)但是,这些现有问题似乎与 TweetSharp 的不同(旧?)版本有关,因为TwitterService.ListFollowersOf()
版本 2.3.0 中没有方法。