通过 Feed 请求在 JSON 中获取更多详细信息

Get more details in JSON with feed request

我在 android 设备上使用 Facebook SDK。我想要每个 post 的所有信息(创建时间、ID、消息、图像 link 和 link)。这是我的代码:

 Bundle parameters = new Bundle();
 parameters.putString("limit", "100");
 final String[]cmb=new String[100];
            new GraphRequest(
                    AccessToken.getCurrentAccessToken(),
                    "/GAMETIMETV/feed",
                    parameters,
                    HttpMethod.GET,
                    new GraphRequest.Callback() {
                        public void onCompleted(GraphResponse response) {

                            JSONObject json = response.getJSONObject();
                            String[] cmb= new String[100];
                            try {

                                JSONArray arrayId = json.getJSONArray("data");


                                for(int y=0;y<arrayId.length();y++){
                                    cmb[y]=arrayId.getJSONObject(y).getString("id"); //id from json to String array
                                }


                                Bundle parametri = new Bundle();
                                parametri.putString("fields", "link,attachments{media{image}}");    //parameters of the request 

                                for(int i =0;i<cmb.length;i++) {


                                    new GraphRequest(
                                            AccessToken.getCurrentAccessToken(),
                                            "/" + cmb[i].id,
                                            parametri,
                                            HttpMethod.GET,
                                            new GraphRequest.Callback() {
                                                public void onCompleted(GraphResponse response) {


                                                }
                                            }).executeAsync();
                                }


                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }
                    }).executeAsync();

这段代码很重,我可以有 post link 和图像 link 而不做另一个请求吗?

是的,您可以将其合并为一个 API 调用:

/GAMETIMETV/feed?limit=100&fields=message,created_time,link,attachments{media{image}}

...或者在您的代码中像这样:

Bundle parameters = new Bundle();
parameters.putString("limit", "100");
parameters.putString("fields", "message,created_time,link,attachments{media{image}}");