0

I'm trying to get all friends of a user ID. But I don't understand how to do paging. This is my code:

ResponseList<Friend> results = facebook.getFriends(USER_ID);   
ArrayList<String> friendList = new ArrayList<String>();

// Getting Next page
Paging<Friend> paging1 = results.getPaging();
for (int i = 0; i < results.size(); i++) {  
    Friend f = results.get(i);
    String id = f.getId().toString();
    friendList.add(id);
    System.out.println(id);
}  

ResponseList<Friend> page2 = facebook.fetchNext(paging1);
for (int i = 0; i < page2.size(); i++) {    
    System.out.println(page2.size());
    Friend f = page2.get(i);
    String id = f.getId().toString();
    friendList.add(id);
    System.out.println(id);
}  

With this code, I can only obtain the first 9 friends' IDs. It seems that the second paging doesn't retrieve anything. What's wrong?

Steve
  • 9,270
  • 5
  • 47
  • 61
ntrax
  • 457
  • 4
  • 22
  • It would be more useful to put `System.out.println(page2.size());` before your loop for iterating through the second page. At least that way, you will see how large page 2 is. Also, not sure why you are not using `for (Friend f : page2)`, which is more readable and less code. – Steve Apr 07 '15 at 10:22

1 Answers1

2

Does not look like paging is your problem if you only get 9 IDs. Most likely only 9 of your friends authorized the App. More information: Get ALL User Friends Using Facebook Graph API - Android

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • if i try to obtain my friends with graph api explorer of facebook, first paging show only 9 friends and the link for paging – ntrax Apr 07 '15 at 09:58
  • 1
    what happens if you use the link for paging in the api explorer? do you get more friends? – andyrandy Apr 07 '15 at 10:05
  • exactly. there are only 9 friends who authorized your app, so there should actually not be paging. – andyrandy Apr 07 '15 at 10:21