获取页面个人资料图片Graph API android

时间:2015-10-28 08:00:47

标签: android facebook-graph-api

我想获取一个页面的个人资料图片。 这是代码,但我不知道如何获取图像:

new GraphRequest(AccessToken.getCurrentAccessToken(), 
                 "/174034509278825/picture",
                 null,
                 HttpMethod.GET,
                 new GraphRequest.Callback() 
                 {
                     public void onCompleted(GraphResponse response) {
                         try { }
                         catch (JSONException e) 
                         {
                             e.printStackTrace();
                         }
                      }

                 }    
                 ).executeAsync();

1 个答案:

答案 0 :(得分:2)

获取个人资料照片中的响应json:

{
    "data": {
    "is_silhouette": false,
    "url": "picture-url"
  },
}

我的解决方案代码:

   AccessToken accessToken = new AccessToken({access-token}
                        , {app-id}, {user-id}
                        , null, null, null, null, null);

                GraphRequest request = GraphRequest.newGraphPathRequest(
                        accessToken,
                        "/{user-id}/picture",
                        new GraphRequest.Callback() {
                            @Override
                            public void onCompleted(GraphResponse response) {
                                try {
                                    JSONObject responseJSONObject = response.getJSONObject();
                                    JSONObject data =  responseJSONObject.getJSONObject("data");

                                    Log.i("your tag", "picture url = "+data.getString("url"));
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        });

                Bundle parameters = new Bundle();
                parameters.putString("redirect", "false");
                request.setParameters(parameters);
                request.executeAsync();