https://dev.twitter.com/docs/api/1.1/get/friends/list URL のTwitter のドキュメントによると 、デフォルトの 20 から「カウント」(ページごとに返されるユーザーの数) の値を変更できます。 200まで。しかし、Twitter4J Javaライブラリを使用してgetFriendsList apiを呼び出すときに、countオプションを指定するにはどうすればよいですか。
質問する
833 次
5 に答える
1
count パラメータは現在(3.0.3 の時点で) Twitter4J では使用されていません。問題のコードは次のようになります。
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));
}
于 2013-10-04T20:29:26.080 に答える
1
According to the documentation if you're using getFriendsList
you can only request up to 20 at a time. Might be a limitation of this 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.
于 2013-10-04T18:49:15.317 に答える
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);
}
他にページング可能な応答がない場合、つまりこれ以上友人リストがない場合、Twitter 応答のカーソル値は 0 になります。
于 2014-03-21T10:15:24.887 に答える
0
Twitter4J でより多くのユーザーを取得するには、カーソルを使用して複数の 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);
注: ゼロのカーソル値は、それ以上結果がないことを意味します。
于 2013-10-07T07:39:06.817 に答える
0
これに対する修正は、2014 年 4 月 29 日にコードにチェックインされ (このコミットを参照)、今日の 4.0.2 スナップショット ビルドで利用できます。したがって、これは v 4.0.2 以降の一部になります。
于 2014-05-22T00:34:08.610 に答える