Last.fm Java API-如何从PaginatedResult获取用户 [英] Last.fm java API - how to get users from PaginatedResult
问题描述
我对lastfm API感到困惑,更确切地说是关于PaginatedResult
I am a but puzzled about the lastfm API, more exactly about the PaginatedResult
我从PaginatedResult中的组中读取了所有用户:
I read all users from a group in a PaginatedResult:
PaginatedResult<de.umass.lastfm.User> users = Group.getMembers("Classic Rock", key);
然后,我尝试了两种方法来显示所有用户.应该有大约25000,但是我只能得到25.只有首页吗?我如何获得所有结果?
Then I tried two methods to display all the users. There should be about 25000, but I only get about 25. Only first page? How could I get all the results?
// for (int i = 0; i < users.getTotalPages();i++){
for (User thisuser: users.getPageResults()){
//for each user
System.out.print(thisuser.getName() + " - age: " + thisuser.getAge() + " - country: " + thisuser.getCountry() + " - "+ thisuser.getGender() + " - is: " + thisuser.getId() + " - playcount: " + thisuser.getPlaycount() + " - num playlists: " + thisuser.getNumPlaylists() + "\n");
}
// }
for (User thisuser: users){
//for each user
System.out.print(thisuser.getName() + " - age: " + thisuser.getAge() + " - country: " + thisuser.getCountry() + " - "+ thisuser.getGender() + " - is: " + thisuser.getId() + " - playcount: " + thisuser.getPlaycount() + " - num playlists: " + thisuser.getNumPlaylists() + "\n");
}
推荐答案
您正在使用的getMembers(String group, String apiKey)
方法仅在分页结果中获得 first 页面.您需要使用getMembers(String group, int page, String apiKey)
重载,并在第一页之外的每个要检索的页面上调用它.每个结果都包含有关可用页面数的信息.
The getMembers(String group, String apiKey)
method you're using only gets the first page in the paginated result. You need to use the getMembers(String group, int page, String apiKey)
overload and call it for each page you want to retrieve beyond the first page. Each result contains information about how many pages are available.
并且不要忘记Last.FM API使用规则中有关您可以进行API调用的频率-要获得25000 Classic Rockers所需的1000次调用将需要1.5个小时的时间来检索(两次请求之间间隔5秒).
And don't forget the Last.FM API usage rules about how often you can make API calls - the 1000 calls needed to get the 25000 Classic Rockers would take 1½ hours to retrieve (5 seconds between requests).
从文档;
A
PaginatedResult
由方法返回,结果集可能是这样的 大到需要分页.每个PaginatedResult
都包含 结果页总数,当前页和Collection
个 当前页面的条目.
A
PaginatedResult
is returned by methods which result set might be so large that it needs to be paginated. EachPaginatedResult
contains the total number of result pages, the current page and aCollection
of entries for the current page.
这篇关于Last.fm Java API-如何从PaginatedResult获取用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!