根據twitter文檔https://dev.twitter.com/docs/api/1.1/get/friends/list URL,我可以將「count」(每頁返回的用戶數)的值從默認值20更改爲200.但是,如何指定count選項同時使用Twitter4J Java庫調用getFriendsList api。Twitter中的計數選項getFriendsList
1
A
回答
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.
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及以上版本的一部分。
相關問題
- 1. C#中的Twitter API計數
- 2. Twitter計數參數
- 3. Twitter的API計數參數
- 4. 計算selectize.js中選項的數量
- 5. 如何計算數組中的選項
- 6. 在列的子選項中計數
- 7. 計算列表中選項的數量
- 8. 計數選擇項目(計數IEnumerable)
- 9. 所選選項的計數器
- 10. Twitter Bootstrap選項卡式表
- 11. 從Twitter中選擇菜單項Bootstrap dropdown
- 12. 從另一個函數中調用twitter bootstrap選項卡函數
- 13. Twitter的json計數限制?
- 14. Twitter的textarea計數字符
- 15. 字符串#計數選項
- 16. 如何使用twitter typeahead.js從json數組中選擇控件中的選項
- 17. jQuery Twitter引導選項卡選擇
- 18. 選擇這些項目的項目計數和所有子項的計數
- 19. 計數選項中選擇使用html的修改後的()
- 20. Twitter引導轉到嵌套選項卡的特定選項卡
- 21. Rails:redirect_to特定的Twitter引導選項卡
- 22. 計數數據庫中的選中項目
- 23. c#計數在列表框中選定的選項
- 24. 自定義屬性選項的計數
- 25. facebook和twitter分享計數
- 26. Twitter API 1.1標籤計數
- 27. 選中複選框的計數數量
- 28. Twitter Twitter Button不計算
- 29. Android Studio中的設計選項卡和預覽選項卡
- 30. ArrayList中的計數項目
哪個java/any_other_lang庫支持count選項? –
基於Kai的回答,你可能可以創建自己的方法,也可以將count作爲參數並傳遞給它。 –