【问题标题】:Get All Followers in Twitter with TweetSharp使用 TweetSharp 在 Twitter 中获取所有关注者
【发布时间】:2013-03-22 12:49:23
【问题描述】:

我正在尝试通过使用 TweetSharp 库来吸引所有关注者。在 twitter 的 api 中,它说我们有机会使用游标变量来进行分页,这样我们就可以获得所有关注者。

https://dev.twitter.com/docs/api/1.1/get/followers/list

https://dev.twitter.com/docs/misc/cursoring

但是,有没有机会用 TweetSharp 做这个操作?我正在编写以下代码:

var options = new ListFollowersOptions { ScreenName = input };
IEnumerable<TwitterUser> friends = service.ListFollowers(options);

但是这只会返回前 20 个,然后我将无法跟踪任何朋友。

如果你能帮助我,那就太好了。

谢谢。

【问题讨论】:

    标签: twitter tweetsharp


    【解决方案1】:

    我在 .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;
        }
    }
    

    注意:这可能被视为重复问题。 (请参阅 herehere。)但是,这些现有问题似乎与 TweetSharp 的不同(旧?)版本有关,因为版本 2.3.0 中没有 TwitterService.ListFollowersOf() 方法。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 2014-01-06
    • 1970-01-01
    • 2021-05-22
    • 2013-06-30
    • 2014-03-01
    相关资源
    最近更新 更多