I am fetching the list of friends who use the my android application and show them in listview. The response we get from the call:
GraphRequestAsyncTask graphRequest = new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
}
}
).executeAsync();
is
{
"data": [
{
"name": "Sanjeev Sharma",
"id": "10XXXXXXXXXX40"
},
{
"name": "Avninder Singh",
"id": "1XXXXX30"
},
{
"name": "Saikrishna Tipparapu",
"id": "17XXXXXX98"
},
{
"name": "Perfekt Archer",
"id": "100XXXXX29"
},
{
"name": "Shathyan Raja",
"id": "10XXXXX0"
},
{
"name": "Kenny Tran",
"id": "10XXXXX36164"
},
{
"name": "Lahaul Seth",
"id": "100XXXXX161"
},
{
"name": "Bappa Dittya",
"id": "10XXXXX24"
},
{
"name": "Rahul",
"id": "10XXXXX
},
{
"name": "Suruchi ",
"id": "7XXXXXXXX11"
}
],
"paging": {
"next": "https://graph.facebook.com/76XXXXXXXX28/friends?limit=25&offset=25&__after_id=enc_AdAXXXXX5L8nqEymMrXXXXoYWaK8BXXHrvpXp03gc1eAaVaj7Q"
},
"summary": {
"total_count": 382
}
}
Now how can we parse the next page of the result in android as it is a link for next page? The next page api call will be done through graph api or facebook only?
ifaour has the right idea of how to use pagination with the next, though i think he is right i just wanted to add a recursive way to fetch all results page after page into one nice list object, this is from a project requesting user photos but its the same idea and syntax as the likes (note that this whole thing is using the execute and wait so you'll have to run this from a separate thread or you will effectively block your UI thread and eventually make the app shut itself down.
Now all you need to do is simply make the initial request and set the callback you've made in previous step, the callback will handle all the dirty work of calling the rest of the items, this will eventually give you all the items from your request.