Android facebook sdk分页

时间:2015-09-02 10:08:20

标签: java android facebook facebook-graph-api facebook-sdk-4.0

facebook sdk的新手。我试图通过图形API获取所有照片。能够通过分页字段获得结果。我想要完成上一个和下一个。但前一个和下一个似乎不是一个网址。我引用了facebook开发者文档,但未找到任何样本。谁来帮帮我。这是我的代码

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();

这是一个示例回复:

  

09-02 15:31:11.794:D / Response(1523):响应{Response:responseCode:200,graphObject:{&#34; data&#34;:[{&#34; id&#34;: &#34; 785636858147560&#34;},{&#34; ID&#34;:&#34; 653561304732935&#34;},{&#34; ID&#34;:&#34; 10152196967129315&#34;}, {&#34; ID&#34;:&#34; 504111853031524&#34;},{&#34; ID&#34;:&#34; 724361997575090&#34;},{&#34; ID&#34 ;: &#34; 10201722174609862&#34;},{&#34; ID&#34;:&#34; 553468811388609&#34;}],&#34;寻呼&#34; {&#34;光标&#34 ;: {&#34;后&#34;:&#34; TlRVek5EWTRPREV4TXpnNE5qQTVPakV6TnprMk5USTJOVFE2TXprME1EZAzVOalF3TmpRM09ETTIZD&#34;&#34;前&#34;:&#34; TnpnMU5qTTJPRFU0TVRRM05UWXdPakUwTURVNU1qRXlORGM2TXprME1EZAzVOalF3TmpRM09ETTIZD&#34;}}},错误:空}

样本响应响应不包含上一个和下一个。相反,它只包含之前和之后。那么,我如何在此代码中使用分页。提前致谢

1 个答案:

答案 0 :(得分:0)

你是对的。它不是网址。要访问分页数据,您应该在= {=您得到的结果}之前附加到您的请求