0

I am working with the Java API of lastfm.

I want to extract all users from a group, say Belgium. How do I create a new group and extract their members?

Group mygroup = new Group();
PaginatedResult<de.umass.lastfm.User> users = mygroup.getMembers("Belgium", key);)

It gives me an error on the first line:

group() has private access.

This is a bit strange. How should I call the constructor and don't I have to pass the group name during construction?

Thanks for any insights!

dorien
  • 5,265
  • 10
  • 57
  • 116

1 Answers1

2

You are correct that the Group has a private constructor, and you cannot use it.

Looking at the source code the method called

 public static PaginatedResult<User> getMembers(String group, int page, String apiKey)

in de.umass.lastfm.Group lets you get all users, and it is static, so you can access it without creating a Group object first.

Do something like

PaginatedResult<de.umass.lastfm.User> users = Group.getMembers("Belgium", key);
thordy
  • 46
  • 4
  • Thanks! That works. Just a small side question. How do I properly loop through all the results of PaginatedResult? The for each loop doesn't give me all results: PaginatedResult users = Group.getMembers("Classic Rock", key); for (User thisuser: users){ System.out.print(thisuser.getName() + " - age: " + thisuser.getAge() + " - country: " + thisuser.getCountry(). + " - "+ thisuser.getGender() + " - is: " + thisuser.getId() + " - playcount: " + thisuser.getPlaycount() + " - num playlists: " + thisuser.getNumPlaylists() + "\n"); } – dorien Mar 24 '14 at 15:17
  • 1
    What do you mean that you do not get all the results? What are you expecting to get? Try using an Iterator instead over the PaginatedResult, and see if that works. – thordy Mar 24 '14 at 17:00
  • Thanks I will try that. I think I only get the first page now. – dorien Mar 24 '14 at 17:27
  • 1
    @thordy, I know you were guessing, but for reference, [that's not how the API works](http://stackoverflow.com/questions/22617045/last-fm-java-api-how-to-get-users-from-paginatedresult/22617291#22617291). The paginated result is one page in the result, so its iterator iterates over results in the page. Strange API design. – bzlm Mar 24 '14 at 18:15