Android - get facebook profile picture

后端 未结 28 2383
花落未央
花落未央 2020-12-12 15:13

I don\'t know why, but I am always getting null when I try to get the profile picture of the user. Do I need to set some specific permissions to get access?

Below is

28条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 15:30

    You have to call GraphRequest API for getting URL of current Profile Picture.

    Bundle params = new Bundle();
    params.putString("fields", "id,email,picture.type(large)");
    new GraphRequest(AccessToken.getCurrentAccessToken(), "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");
                                Bitmap profilePic = BitmapFactory.decodeStream(profilePicUrl.openConnection().getInputStream());
                                // set profilePic bitmap to imageview
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
    }).executeAsync();
    

    I hope it helps!

提交回复
热议问题