2013-03-22 8 views
1

TweetSharp 라이브러리를 사용하여 모든 팔로워를 얻으려고합니다. 트위터의 API에서는 커서 변수를 사용하여 페이지 매김을 수행하여 모든 팔로어를 얻을 수있는 기회가 있다고합니다.TweetSharp로 트위터의 모든 팔로워 받기

https://dev.twitter.com/docs/api/1.1/get/followers/list

https://dev.twitter.com/docs/misc/cursoring

그러나, TweetSharp으로이 작업을 할 수있는 기회가있다? 다음 코드를 작성합니다 :

var options = new ListFollowersOptions { ScreenName = input }; 
IEnumerable<TwitterUser> friends = service.ListFollowers(options); 

그러나 처음 20 개만 반환하면 다른 친구를 추적 할 수 없습니다.

나를 도울 수 있다면 좋을 것입니다.

감사합니다.

답변

1

.NET 4.0 WinForms 앱에서 TweetSharp v2.3.0을 사용하고 있습니다. 다음은 나를위한 것입니다.

// this code assumes that your TwitterService is already properly authenticated 

TwitterUser tuSelf = service.GetUserProfile(
    new GetUserProfileOptions() { IncludeEntities = false, SkipStatus = false }); 

ListFollowersOptions options = new ListFollowersOptions(); 
options.UserId = tuSelf.Id; 
options.ScreenName = tuSelf.ScreenName; 
options.IncludeUserEntities = true; 
options.SkipStatus = false; 
options.Cursor = -1; 
List<TwitterUser> lstFollowers = new List<TwitterUser>(); 

TwitterCursorList<TwitterUser> followers = service.ListFollowers(options); 

// if the API call did not succeed 
if (followers == null) 
{ 
    // handle the error 
    // see service.Response and/or service.Response.Error for details 
} 
else 
{ 
    while (followers.NextCursor != null) 
    { 
     //options.Cursor = followers.NextCursor; 
     //followers = m_twService.ListFollowers(options); 

     // if the API call did not succeed 
     if (followers == null) 
     { 
      // handle the error 
      // see service.Response and/or service.Response.Error for details 
     } 
     else 
     { 
      foreach (TwitterUser user in followers) 
      { 
       // do something with the user (I'm adding them to a List) 
       lstFollowers.Add(user); 
      } 
     } 

     // if there are more followers 
     if (followers.NextCursor != null && 
      followers.NextCursor != 0) 
     { 
      // then advance the cursor and load the next page of results 
      options.Cursor = followers.NextCursor; 
      followers = service.ListFollowers(options); 
     } 
     // otherwise, we're done! 
     else 
      break; 
    } 
} 

참고 :이 질문은 중복되는 것으로 간주 될 수 있습니다. (herehere을 참조하십시오.) 그러나 기존 질문은 버전 2.3.0에 TwitterService.ListFollowersOf() 메서드가 없기 때문에 다른 TweetSharp 버전과 관련이있는 것으로 보입니다.

+1

감사합니다. 예상대로 작동합니다. v1.1 트위터 만 사용하면 15 요청/15 분만 허용됩니다. https://dev.twitter.com/docs/rate-limiting/1.1/ 여기를 참조하십시오. 당신이 얻을 수있는 fowllowers의 최대 수는 15 분에 300입니다 :) – hriziya

+0

@HiteshRiziya [follow followers/ids] (https://dev.twitter.com/docs/api/1.1/get/followers/ids)를 사용할 수 있습니다.)와 [GET users/lookup] (https://dev.twitter.com/docs/api/1.1/get/users/lookup)을 사용하여 15 분 안에 최대 18000 명의 팔로어를 확보 할 수 있습니다. –