简体   繁体   中英

Facebook4j paging to get all friends

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM