Reputation: 786
I am building an application that fetches the images of a facebook user. I have parsed the returned JSONObject, extracted the URL of the images and load them into a GridView.
The Problem is that the JSONObject have link to second pages to fetch the remaining images's.
Here is my code:
final GraphRequest.Callback graphCallback = new GraphRequest.Callback(){
@Override
public void onCompleted(GraphResponse response) {
jsonObject = response.getJSONObject();
GraphRequest newRequest = response.getRequestForPagedResults(GraphResponse.PagingDirection.NEXT);
JSONObject object = request.getGraphObject();
}
};
Bundle parameters = new Bundle();
parameters.putString("fields", "images");
parameters.putString("limit", "50");
Bundle tagged = new Bundle();
tagged.putString("type", "tagged");
final GraphRequest request = new GraphRequest( AccessToken.getCurrentAccessToken(), "/" + profile.getId() + "/photos", tagged,
HttpMethod.GET, graphCallback
);
request.setParameters(parameters);
request.executeAsync();
Here is the value of the newRequest:
{Request: accessToken: {AccessToken token:ACCESS_TOKEN_REMOVED permissions:> [user_friends, user_photos, public_profile]}, graphPath: null, graphObject: null, httpMethod: GET, parameters: Bundle[{}]}
And the value of the JSONObject "object" is :
null
how to implement pagination using FacebookSDK
Thanks for helping!!
Upvotes: 0
Views: 562
Reputation: 786
Now i found the solution. First of all the newRequest object is not null. When I debug the code, I looked for the difference between the newRequest (GraphRequest) and the request (GraphRequest).
There are 2 things missing:
Therefore, my code becomes as follows:
final GraphRequest.Callback graphCallback = new GraphRequest.Callback(){
@Override
public void onCompleted(GraphResponse response) {
Bundle parameters = new Bundle();
parameters.putString("fields", "images");
parameters.putString("limit", "50");
jsonObject = response.getJSONObject();
GraphRequest newRequest = response.getRequestForPagedResults(GraphResponse.PagingDirection.NEXT);
newRequest.setGraphPath("/" + profile.getId() + "/photos");
newRequest.setCallback(this);
newRequest.setParameters(parameters);
newRequest.executeAsync();
}
};
This is how Pagination is implemented with facebookSDK
Upvotes: 1