I am a but puzzled about the lastfm API, more exactly about the PaginatedResult
I read all users from a group in a PaginatedResult:
PaginatedResult<de.umass.lastfm.User> users = Group.getMembers("Classic Rock", key);
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");
}
The
getMembers(String group, String apiKey)
method you're using only gets the first page in the paginated result. You need to use thegetMembers(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.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).
From the documentation;