【问题标题】:How to get fb user photos in android?如何在android中获取fb用户照片?
【发布时间】:2017-07-24 13:01:10
【问题描述】:

我尝试通过以下方式通过 GraphRequest 检索 facebook 用户照片 代码:

enter code here  final ArrayList[] alFBAlbum = new ArrayList[]{new ArrayList<>()};

/*make API call*/
    new GraphRequest(
            AccessToken.getCurrentAccessToken(),  //your fb AccessToken
            "/" + AccessToken.getCurrentAccessToken().getUserId() + "/albums",//user id of login user
            null,
            HttpMethod.GET,
            new GraphRequest.Callback() {
                public void onCompleted(GraphResponse response) {
                    Log.d("fb_album_response", "Facebook Albums: " + response.toString());
                    try {
                        if (response.getError() == null) {
                            JSONObject joMain = response.getJSONObject(); //convert GraphResponse response to JSONObject
                            if (joMain.has("data")) {
                                JSONArray jaData = joMain.optJSONArray("data"); //find JSONArray from JSONObject
                                alFBAlbum[0] = new ArrayList<>();
                                for (int i = 0; i < jaData.length(); i++) {//find no. of album using jaData.length()
                                    JSONObject joAlbum = jaData.getJSONObject(i);
                                    String my_id=joAlbum.optString("id");//convert perticular album into JSONObject
                                    Log.d("my_facebook_id",my_id);
                                    GetFacebookImages(my_id); //find Album ID and get All Images from album
                                }
                            }
                        } else {
                            Log.d("Test",response.getError().toString());
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }

    ).executeAsync();

通过使用此 cod,我可以获得 fb 用户相册,但它返回空数组 像这样:

enter code here  {
  "data":[]
 }, 
   error: null
  }

你能告诉我如何获取 fb 用户照片吗?

【问题讨论】:

标签: android facebook facebook-graph-api


【解决方案1】:

您已从 Facebook 帐户向get photos 提出请求。在搜索了数小时 Facebook 开发人员页面后,我得到了您问题的解决方案,我提供了获取 Facebook 用户照片的链接,请遵循。
链接: https://developers.facebook.com/docs/graph-api/reference/photo/#Reading

/* make the API call */
Bundle params  = new Bundle();
bundle.putExtra("fields","images");

new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/"+"USER ID"+"/photos",
params,
HttpMethod.GET,
new GraphRequest.Callback() {
    public void onCompleted(GraphResponse response) {
        /* handle the result */
         /* You can parse this response using Json  */
    }
}
).executeAsync();

【讨论】:

  • 很好的答案,但是如何按日期按顺序获取图像?最新的 50 个假设
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-09-07
  • 2012-12-18
  • 1970-01-01
  • 2023-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多