Android - get facebook profile picture

后端 未结 28 2378
花落未央
花落未央 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:52

    I always received a response stating a FACEBOOK_NON_JSON_RESULT. So looking back in Facebook’s graph API explorer I noted a little checkbox with the label redirect checked. Some googling showed me that I needed to provide a parameter to my GraphRequest that disallows the redirect. Hence the correct request must be:

     Bundle params = new Bundle();
     params.putBoolean("redirect", false);
    
         new GraphRequest(
         AccessToken.getCurrentAccessToken(),
         "me/picture",
         params,
         HttpMethod.GET,
         new GraphRequest.Callback() {
            public void onCompleted(GraphResponse response) {
                try {
                    String picUrlString = (String) response.getJSONObject().getJSONObject("data").get("url");   
                    //Load picture url in imageView
                    Glide.with(this).load(picUrlString).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(profilePictureView);
                } catch (JSONException | IOException e) {
                    e.printStackTrace();
                }
            }
        }
     ).executeAsync();                                      
    

提交回复
热议问题