TweetSharp get followers count
Does anyone know how to use TweetShar开发者_运维问答p to get some account's follower count?
You can get the friends and followers count from the TwitterUser object. To fetch a user directly:
var twitter = FluentTwitter.CreateRequest()
.Users().ShowProfileFor("jimbob").AsJson();
var response = twitter.Request();
var user = response.AsUser();
Console.Writeline( "jimbob has {0} followers", user.FollowersCount);
User objects are also returned with individual TwitterStatus objects (i.e. tweets), so you can get them straight from there and avoid making another call as well:
var twitter = FluentTwitter.CreateRequest()
.Statuses().OnHomeTimeline().AsJson();
var response = twitter.Request();
var tweets = response.AsTweets();
foreach ( var tweet in tweets )
{
Console.Writeline( "Posted by {0}, who has {1} followers", tweet.User.ScreenName, tweet.User.FollowersCount);
}
I know this is old, but this works for the new version better than nityan's answer, since Twitter's API doesn't return all their followers at once.
Basically just do a search for the account you want and it returns their profile including follower count.
const string consumerKey = "consumerKey";
const string consumerSecret = "consumerSecret";
const string accessToken = "accessToken";
const string accessTokenSecret = "accessTokenSecret";
string handleToSearchFor = "stackoverflow";
var service = new TwitterService(consumerKey, consumerSecret);
service.AuthenticateWith(accessToken, accessTokenSecret);
var users = service.SearchForUser(new SearchForUserOptions { Q = handleToSearchFor});
foreach (var user in users)
{
Console.WriteLine("{0} has {1} followers and follows {2} people!", user.ScreenName, user.FollowersCount, user.FriendsCount);
}
public void Method() {
IList<TwitterUser> twitterFollowers = null;
ListFollowersOptions options = new ListFollowersOptions();
options.ScreenName = screenName;
twitterFollowers = service.ListFollowers(options);
int followersCount = twitterFollowers.Count;
}
精彩评论