我正在构建一个获取Facebook用户的图像的应用程序。我已经解析了返回的 JSONObject ,提取了图像的URL并将它们加载到GridView中。
问题是JSONObject有第二页的链接来获取剩余的图像。
这是我的代码:
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();
这是newRequest的值:
{请求:accessToken:{AccessToken令牌:ACCESS_TOKEN_REMOVED权限:> [user_friends,user_photos,public_profile]},graphPath:null,graphObject:null,httpMethod:GET,parameters:Bundle [{}]}
JSONObject“对象”的值是:
空
如何使用FacebookSDK实现分页
感谢您的帮助!!
答案 0 :(得分:1)
现在我找到了解决方案。首先,newRequest对象是 not null 。当我调试代码时,我寻找newRequest(GraphRequest)和请求(GraphRequest)之间的区别。
缺少两件事:
因此,我的代码如下:
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();
}
};
这是使用facebookSDK实现分页的方式