Android : How to get larger profile pic from Facebook using FirebaseAuth?

后端 未结 8 565
孤街浪徒
孤街浪徒 2021-01-30 14:25

I am using FirebaseAuth to login user through FB. Here is the code:

private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
pr         


        
8条回答
  •  醉梦人生
    2021-01-30 15:09

    It is not possible to obtain a profile picture from Firebase that is larger than the one provided by getPhotoUrl(). However, the Facebook graph makes it pretty simple to get a user's profile picture in any size you want, as long as you have the user's Facebook ID.

    String facebookUserId = "";
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    ImageView profilePicture = (ImageView) findViewById(R.id.image_profile_picture);
    
    // find the Facebook profile and get the user's id
    for(UserInfo profile : user.getProviderData()) {
        // check if the provider id matches "facebook.com"    
        if(FacebookAuthProvider.PROVIDER_ID.equals(profile.getProviderId())) {
            facebookUserId = profile.getUid();
        }
    }
    
    // construct the URL to the profile picture, with a custom height
    // alternatively, use '?type=small|medium|large' instead of ?height=
    String photoUrl = "https://graph.facebook.com/" + facebookUserId + "/picture?height=500";
    
    // (optional) use Picasso to download and show to image
    Picasso.with(this).load(photoUrl).into(profilePicture);
    

提交回复
热议问题