简体   繁体   English

Android Facebook SDK分页

[英]Android facebook sdk Pagination

Am new to facebook sdk. 是Facebook SDK的新手。 I'm trying to get all of my photos through graph API. 我正在尝试通过图形API获取所有照片。 Am able to get the result with the paging field. 能够通过分页字段获取结果。 I want to move through the previous and next. 我想浏览上一个和下一个。 But the previous and next doesn't seems to be an url. 但是上一个和下一个似乎不是URL。 I refere the facebook developer documentation but couldnt found any samples. 我参考了Facebook开发人员文档,但找不到任何示例。 Someone help me. 谁来帮帮我。 This is my code 这是我的代码

GraphRequest graphRequest = new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            "/"+userID+"/photos",
            null,
            HttpMethod.GET,
            new GraphRequest.Callback() {
                @Override
                public void onCompleted(GraphResponse response) {
                    // TODO Auto-generated method stub
                    Log.d("Response ","Response " + response);

                    JSONObject json = response.getJSONObject();
                    JSONArray jarray = null;
                    try{
                        jarray = json.getJSONArray("data");
                        if(jarray != null){
                            // Loop through the "data" and get the id
                            for (int i = 0, len = jarray.length(); i < len; i++) {
                                JSONObject item = jarray.getJSONObject(i);
                                noOfRequest++;
                                downloadFbPhotos(item.getString("id"));
                            }
                        }


                        if(!json.isNull("paging")) {
                            JSONObject paging = json.getJSONObject("paging");
                            JSONObject cursors = paging.getJSONObject("cursors");
                            if (!cursors.isNull("after")){
                                after = cursors.getString("after");
                            }
                            else{
                                //no after
                            }
                        }
                    }
                    catch(JSONException e){
                        //
                    }
                }
            }
        );

        Bundle parameters = new Bundle();
        parameters.putString("fields", "data,paging");
        //parameters.putString("limit", "100");
        //parameters.putString("offset", "1");
        //parameters.putString("after", "");
        graphRequest.setParameters(parameters);
        graphRequest.executeAsync();

This is a sample response: 这是一个示例响应:

09-02 15:31:11.794: D/Response(1523): Response {Response: responseCode: 200, graphObject: {"data":[{"id":"785636858147560"},{"id":"653561304732935"},{"id":"10152196967129315"},{"id":"504111853031524"},{"id":"724361997575090"},{"id":"10201722174609862"},{"id":"553468811388609"}],"paging":{"cursors":{"after":"TlRVek5EWTRPREV4TXpnNE5qQTVPakV6TnprMk5USTJOVFE2TXprME1EZAzVOalF3TmpRM09ETTIZD","before":"TnpnMU5qTTJPRFU0TVRRM05UWXdPakUwTURVNU1qRXlORGM2TXprME1EZAzVOalF3TmpRM09ETTIZD"}}}, error: null} 09-02 15:31:11.794:D / Response(1523):响应{Response:responseCode:200,graphObject:{“ data”:[{“ id”:“ 785636858147560”},{“ id”:“ 653561304732935” },{“ id”:“ 10152196967129315”},{“ id”:“ 504111853031524”},{“ id”:“ 724361997575090”}},{“ id”:“ 10201722174609862”},{“ id”:“ 553468811388609” }],“ paging”:{“ cursors”:{“ after”:“ TlRVek5EWTRPREV4TXpnNE5qQTVPakV6TnprMk5USTJOVFE2TXprME1EZAzVOalF3TmpRM09ETTIZD”,“之前”:“ TnpnMU5qTTJPRF0ZRZUWZDW1MZUWZDW1MZUW {TwN}

The sample response response doesn't contains previous and next. 样本响应响应不包含上一个和下一个。 Instead it contains only before and after. 相反,它仅包含之前和之后。 So, How do I use the paging in this code. 因此,如何在此代码中使用分页。 Thanks in advance 提前致谢

You are right. 你是对的。 It's not url. 不是网址。 To access paginate data you should attach before/after={the thing you get in result} to your request 要访问分页数据,您应该在请求之前/之后附加{您得到的结果}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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