Find all followers for a user using Linq to Twitte

2019-07-22 19:58发布

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.

3条回答
趁早两清
2楼-- · 2019-07-22 20:41

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楼-- · 2019-07-22 20:51

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

查看更多
Viruses.
4楼-- · 2019-07-22 20:57

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

查看更多
登录 后发表回答