Retrieve profile picture using Facebook SDK 3.0 for Android

前端 未结 6 1713
Happy的楠姐
Happy的楠姐 2021-02-19 03:24

I\'ve following problem with Facebook SDK 3.0 for Android. I wanna get my (and my friends) profile picture without using their ProfilePictureView widget, so if I use Graph Explo

6条回答
  •  悲哀的现实
    2021-02-19 04:15

    You can get the profile picture by requesting to the Graph API. You need to pass the accessToken ,the user ID and also set the redirect false. Then the Graph API returns the JSON and from the JSON you can get url field which is the user profile.

      GraphRequest request = new GraphRequest(accessToken, "/" + userID + "/picture",null,HttpMethod.GET, new GraphRequest.Callback() {
                    @Override
                    public void onCompleted(GraphResponse response) {
                        Log.d("Photo Profile", response.getJSONObject().toString());
                        JSONObject jsonObject = response.getJSONObject();
                        try {
    
                            JSONObject data = jsonObject.getJSONObject("data");
                            String url = data.getString("url");
                            Picasso.with(getApplicationContext()).load(url).into(ivProfilePicture);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
                Bundle parameters =new Bundle();
                parameters.putString("type","large");
                parameters.putBoolean("redirect",false);
                request.setParameters(parameters);
                request.executeAsync();
    

提交回复
热议问题