gpt4 book ai didi

java - Last.fm java API - 如何从 PaginatedResult 获取用户

转载 作者:太空宇宙 更新时间:2023-11-04 06:56:49 26 4
gpt4 key购买 nike

我对 Lastfm API 感到困惑,更确切地说是对 PaginationResult 感到困惑

我在 PaginationResult 中读取了某个组中的所有用户:

PaginatedResult<de.umass.lastfm.User> users = Group.getMembers("Classic Rock", key);

然后我尝试了两种方法来显示所有用户。应该有25000左右,但我只得到了25左右。只有第一页?我怎样才能得到所有结果?

//        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) 方法仅获取分页结果中的第一页。您需要使用 getMembers(String group, int page, String apiKey) 重载,并为您想要检索的第一页之外的每个页面调用它。每个结果都包含有关可用页面数的信息。

并且不要忘记有关 API 调用频率的 Last.FM API 使用规则 - 获取 25000 个经典摇杆所需的 1000 次调用将需要 1.5 小时才能检索(请求之间间隔 5 秒)。

来自documentation ;

A PaginatedResult is returned by methods which result set might be so large that it needs to be paginated. Each PaginatedResult contains the total number of result pages, the current page and a Collection of entries for the current page.

关于java - Last.fm java API - 如何从 PaginatedResult 获取用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22617045/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com