Getting the “real” Facebook profile picture URL from graph API

后端 未结 12 2054
说谎
说谎 2020-12-12 15:25

Facebook graph API tells me I can get a profile picture of a user using

http://graph.facebook.com/517267866/picture?type=large

which works fine. However, whe

12条回答
  •  余生分开走
    2020-12-12 16:18

    For Android:

    According to latest Facebook SDK,

    First you need to call GraphRequest API for getting all the details of user in which API also gives URL of current Profile Picture.

    Bundle params = new Bundle();
    params.putString("fields", "id,email,gender,cover,picture.type(large)");
    new GraphRequest(token, "me", params, HttpMethod.GET,
            new GraphRequest.Callback() {
                @Override
                public void onCompleted(GraphResponse response) {
                    if (response != null) {
                        try {
                            JSONObject data = response.getJSONObject();
                            if (data.has("picture")) {
                                String profilePicUrl = data.getJSONObject("picture").getJSONObject("data").getString("url");
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
    }).executeAsync();
    

提交回复
热议问题