Find all followers for a user using Linq to Twitter?

我只是一个虾纸丫 提交于 2019-12-24 17:23:47

问题


How can I find all the followers a Twitter user has using Linq2Twitter?

All I can find in the documentation is a reference to the .Following property, not the .Followers property.

var result = from search in context.List
             where search.Following //etc

How can I find the followers a Twitter user has if I provide the twitter username?

twitter.com/foobar // 'foobar' is the username.

回答1:


LINQ to Twitter lets you query the social graph for friends and followers. Here's an example of how to get followers:

        var followers =
            (from follower in twitterCtx.SocialGraph
             where follower.Type == SocialGraphType.Followers &&
                   follower.ID == "15411837"
             select follower)
            .SingleOrDefault();

        followers.IDs.ForEach(id => Console.WriteLine("Follower ID: " + id));

That will return IDs. Here's the full documentation: http://linqtotwitter.codeplex.com/wikipage?title=Listing%20Followers&referringTitle=Listing%20Social%20Graphs.

Joe




回答2:


The Twitter API is GET followers/ids so I have to guess that the Linq2Twitter code is probably something like the following:

var users = from tweet in twitterCtx.User
                where tweet.Type == UserType.Show &&
                      tweet.ScreenName == "Sergio"
                select tweet;   
var user = users.SingleOrDefault();

var followers = user.Followers;



回答3:


The following code demonstrates how to get all followers of a particular user

var followers =
            await
            (from follower in twitterCtx.Friendship
             where follower.Type == FriendshipType.FollowerIDs &&
                   follower.UserID == "15411837"
             select follower)
            .SingleOrDefaultAsync();

        if (followers != null && 
            followers.IDInfo != null && 
            followers.IDInfo.IDs != null)
        {
            followers.IDInfo.IDs.ForEach(id =>
                Console.WriteLine("Follower ID: " + id)); 
        }

Source: Linq2Twitter Github

Note: This method call is limited to 5000 followers only. If you just need the count of followers, it might be better to scrape it off the twitter website



来源:https://stackoverflow.com/questions/10724064/find-all-followers-for-a-user-using-linq-to-twitter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!