2013-10-04 21 views

回答

1

根據documentation如果您使用getFriendsList您一次最多隻能請求20個。可能是該Java API

PagableResponseList<User> getFriendsList(long userId, 
            long cursor) 
            throws TwitterException 
cursor - Causes the results to be broken into pages of no more than 20 records at a time. 
+0

哪個java/any_other_lang庫支持count選項? –

+0

基於Kai的回答,你可能可以創建自己的方法,也可以將count作爲參數並傳遞給它。 –

1

count parameter的限制在Twitter4J在時刻(作爲3.0.3)不被使用。 這是什麼問題looks like代碼:

public PagableResponseList<User> getFriendsList(long userId, long cursor) throws TwitterException { 
    return factory.createPagableUserList(get(conf.getRestBaseURL() 
     + "friends/list.json?user_id=" + userId 
     + "&cursor=" + cursor)); 
} 

public PagableResponseList<User> getFriendsList(String screenName, long cursor) throws TwitterException { 
    return factory.createPagableUserList(get(conf.getRestBaseURL() 
     + "friends/list.json?screen_name=" + screenName 
     + "&cursor=" + cursor)); 
} 
0

爲了獲取更多的用戶與Twitter4J你將不得不使用cursors,使多個API調用,例如:

long cursor = -1; 
PagableResponseList<User> friends; 
do { 
    friends = twitter.getFriendsList(userId, cursor); 
    // collect users be adding to list etc... 
} while ((cursor = followers.getNextCursor()) != 0); 

NB遊標值爲零表示沒有其他結果。

0

您的代碼應該這樣看:

 long cursor=-1; 
    int count=0; 

    while(cursor!=0) 
    { 
      PagableResponseList<User> friendlist= twitter.getFriendsList(user.getScreenName(),cursor); 
      int sizeoffreindlist= friendlist.size(); 
      for(int i=0;i<sizeoffreindlist;i++) 
     { 

      //System.out.println(friendlist.get(i)); 
        //Your Logic goes here 

     } 
     cursor=friendlist.getNextCursor(); 
     System.out.println("====> New cursor value"+cursor); 
    } 

微博迴應光標值爲0時,即有沒有其他的可分頁的反應是沒有更多的好友列表

+0

這不是問題的解決方案。 – TechCrunch

0

對此問題進行修復是在簽入代碼2014年4月29日(請參閱this commit),現在可以在4.0.2 Snapshot版本中使用。所以這將成爲4.0.2及以上版本的一部分。