I didn\'t find any help on this topic. The Docs say
Cursor-based pagination is the most efficient method of paging and should always be used where possibl
Though it's true that you should use GraphResponse.getRequestForPagedResults(), you can't use executeAndWait()
unless you run it in a different thread.
You can make it even easier using executeAsync()
.
To get the first set of results:
new GraphRequest(AccessToken.getCurrentAccessToken(),
"/" + facebookID + "/invitable_friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
//your code
//save the last GraphResponse you received
lastGraphResponse = response;
}
}
).executeAsync();
Use that lastGraphResponse to get the next set of results:
GraphRequest nextResultsRequests = lastGraphResponse.getRequestForPagedResults(GraphResponse.PagingDirection.NEXT);
if (nextResultsRequests != null) {
nextResultsRequests.setCallback(new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
//your code
//save the last GraphResponse you received
lastGraphResponse = response;
}
});
nextResultsRequests.executeAsync();
}
You can merge all that in a single method!