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

Two lines of code. FirebaseUser user = firebaseAuth.getCurrentUser();

String photoUrl = user.getPhotoUrl().toString();
        photoUrl = photoUrl + "?height=500";

simply append "?height=500" at the end


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);

If someone is looking for this but for Google account using FirebaseAuth. I have found a workaround for this. If you detail the picture URL:

https://lh4.googleusercontent.com/../.../.../.../s96-c/photo.jpg

The /s96-c/ specifies the image size (96x96 in this case)so you just need to replace that value with the desired size.

String url= FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl();
url = url.replace("/s96-c/","/s300-c/");

You can analyze your photo URL to see if there is any other way to change its size.

As I said in the begining, this only works for Google accounts. Check @Mathias Brandt 's answer to get a custom facebook profile picture size.

EDIT 2020:

Thanks to Andres SK and @alextouzel for pointing this out. Photo URLs format have changed and now you can pass URL params to get different sizes of the picture. Check https://developers.google.com/people/image-sizing.


photoUrl = "https://graph.facebook.com/" + facebookId+ "/picture?height=500"

You can store this link to firebase database with user facebookId and use this in app. Also you can change height as a parameter