Android: How to get a larger pic profile from fb using firebaseAuth

I use firebaseAuth to log in a user through FB. Here is the code

private FirebaseAuth mAuth; private FirebaseAuth.AuthStateListener mAuthListener; private CallbackManager mCallbackManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getApplicationContext()); // Initialize Firebase Auth mAuth = FirebaseAuth.getInstance(); mAuthListener = firebaseAuth -> { FirebaseUser user = firebaseAuth.getCurrentUser(); if (user != null) { // User is signed in Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid()); } else { // User is signed out Log.d(TAG, "onAuthStateChanged:signed_out"); } if (user != null) { Log.d(TAG, "User details : " + user.getDisplayName() + user.getEmail() + "\n" + user.getPhotoUrl() + "\n" + user.getUid() + "\n" + user.getToken(true) + "\n" + user.getProviderId()); } }; } 

The problem is that the photo I get from using user.getPhotoUrl () is very small. I need a larger image and cannot find a way to do this. Any help would be greatly appreciated. I already tried this. Get a larger facebook image through the firebase login but it doesnโ€™t work, although they are for quick, I donโ€™t think the api should be different.

+7
android firebase firebase-authentication facebook-authentication
source share
3 answers

It is not possible to get the profile image from Firebase, which is larger than the image provided by getPhotoUrl() . However, the Facebook graph makes it quite easy to get a user profile picture in any size if you have a Facebook user 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 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); 
+15
source share

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

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

In this case, / s96-c / sets the image size (in this case, 96x96), so you just need to replace this value with the required size.

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

You can parse your photo url to see if there is another way to resize it.

As I said at the beginning, this only works for Google accounts. Check out @Mathias Brandt answer to get custom image size on facebook profile.

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

You can save this link in the firebase database with facebookId and use it in the application. You can also change the height as a parameter

0
source share

All Articles