在 android 上解析 Facebook 图 API 请求时未获取照片链接

Not getting photos links when parsing Facebook graph API request on android

我正在尝试使用 Facebook SDK 4.0 和图表 API 在 android 上获取用户照片 link。 我写这段代码来解析和获取照片 link -

new GraphRequest(

            AccessToken.getCurrentAccessToken(),
                    "/" + userId + "/photos",
                    null,
                    HttpMethod.GET,
                    new GraphRequest.Callback() {
                        public void onCompleted(GraphResponse response) {

                            JSONObject json = null;

                            try {
                                json = new JSONObject(String.valueOf(response));
                            } catch (JSONException e) {
                                e.printStackTracegetJSONObject();
                            }
                            JSONArray jarray = null;
                            try {
                                jarray = json.getJSONArray("data"); 

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

                            for(int i = 0; i < jarray.length(); i++){
                                oneAlbum = null;
                                try {
                                    oneAlbumURL1 = jarrayjson.getJSONObjectgetString(i"url");
                                } catch (JSONException e) {
                                    einfo.printStackTracesetText(URL1.toString());
                                }

                                String URL1 = null; // 
                                try {
                                  URL1 = String.valueOf(oneAlbum.getJSONObject("link"));
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                Log.d("", URL1);
                            }
                        }
                    }
            ).executeAsync();

但是它既没有显示任何错误也没有得到任何 URLs/links。谁能告诉我这里出了什么问题?

根据新的 Facebook api v2.4,您需要将 fields 参数传递给您的 facebook api url.

喜欢:&fields=来源、id、图片

即:

https://graph.facebook.com/userId/photos?access_token=APP_ACCESS_TOKEN&fields=source,id,picture

您将在源和图片标签中获得图像 url..

编辑

Bundle parameters = new Bundle();
parameters.putString("fields", "source,id,picture");

AccessToken.getCurrentAccessToken(),
                    "/" + userId + "/photos",
                    parameters,
                    HttpMethod.GET,

EDIT-2:

public void onCompleted(GraphResponse response) {
    JSONObject json = response.getJSONObject();
    JSONArray jarray = null;
    try {
        jarray = json.getJSONArray("data");
    } catch (JSONException e) {
        e.printStackTrace();
    }

根据 V.J 给出的答案,我编辑了我的代码,现在它工作得很好。刚刚将 "url" 替换为 "source".

new GraphRequest(

                AccessToken.getCurrentAccessToken(),
                         "/" + userId + "/photos",
                        parameters,
                        HttpMethod.GET,
                        new GraphRequest.Callback() {
                            public void onCompleted(GraphResponse response) {

                                json = response.getJSONObject();
                                Log.d("json value", json.toString());

                                try {

                                    jarray = json.getJSONArray("data");


                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                for(int i = 0; i < jarray.length(); i++){

                                    try {
                                        oneAlbum = jarray.getJSONObject(i);
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }

                                    try {
                                        URL1 = String.valueOf(oneAlbum.getJSONObject("source"));
                                        info.setText(URL1);
                                        Log.d("got URLSSSs", URL1.toString());
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }

                                }
                            }
                        }
                ).executeAsync();