Get user image from Facebook Graph-API

前端 未结 7 620
长发绾君心
长发绾君心 2020-12-01 03:22

I want to show the users profile picture in a list view. When I try to call the graph-api from android to retrieve the image, I always get the following error.

<         


        
相关标签:
7条回答
  • 2020-12-01 03:53

    Use below code to get user profile image with Facebook Graph API.

         ImageView profileImage = (ImageView) findViewById(R.id.profileImage);
         Bundle params = new Bundle();
         params.putBoolean("redirect", false);
         params.putString("type", "large");
              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");
                Glide.with(getApplicationContext()).load(picUrlString).placeholder(R.drawable.ic_launcher).into(profileImage);
              } catch (JSONException | IOException e) {
                e.printStackTrace();
            }
        }
    }
    ).executeAsync();    
    

    And more information refer This

    OR

    Simple to get user image

    String UserImageUrl="https://graph.facebook.com/" + facebookUser.getFacebookID() + "/picture?type=large"; 
    Glide.with(getApplicationContext()).load(UserImageUrl).placeholder(R.drawable.ic_launcher).into(profileImage); 
    
    0 讨论(0)
提交回复
热议问题