2010-02-12 87 views

回答

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); 
} 
+0

您好,我遇到您的答案,但我使用的是2.0版本,'FluentTwitter'不再存在,你知道如何在最新版本中做到這一點嗎? – Ebikeneser 2012-01-10 09:30:10

0
public void Method() {  
    IList<TwitterUser> twitterFollowers = null; 
    ListFollowersOptions options = new ListFollowersOptions(); 

    options.ScreenName = screenName; 
    twitterFollowers = service.ListFollowers(options); 

    int followersCount = twitterFollowers.Count; 
} 
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); 
}