通过Feed请求获取有关JSON的更多详细信息

时间:2016-12-21 07:49:20

标签: android json facebook-graph-api facebook-android-sdk

我使用Facebook SDK安卓设备。我想要每个帖子的所有信息(创建时间,id,消息,imagelink和链接)。这是我的代码:

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

此代码很重,我可以在没有其他请求的情况下发布链接和图像链接吗?

1 个答案:

答案 0 :(得分:2)

是的,您可以将其合并为一个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}}");