有谁知道如何使用TweetSharp获取某个帐户的关注者数量?
答案 0 :(得分:2)
您可以从TwitterUser对象中获取朋友和关注者的数量。直接获取用户:
var twitter = FluentTwitter.CreateRequest()
.Users().ShowProfileFor("jimbob").AsJson();
var response = twitter.Request();
var user = response.AsUser();
Console.Writeline( "jimbob has {0} followers", user.FollowersCount);
用户对象也会与单个TwitterStatus对象(即推文)一起返回,因此您可以直接从那里获取它们,并避免再次拨打电话:
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);
}
答案 1 :(得分:1)
我知道这已经过时了,但是对于新版本而言,这比nityan的答案更有效,因为Twitter的API不会立即归还所有关注者。
基本上只需搜索您想要的帐户,然后返回其个人资料,包括关注者计数。
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);
}
答案 2 :(得分:0)
public void Method() {
IList<TwitterUser> twitterFollowers = null;
ListFollowersOptions options = new ListFollowersOptions();
options.ScreenName = screenName;
twitterFollowers = service.ListFollowers(options);
int followersCount = twitterFollowers.Count;
}