Android Firebase Auth - get user photo

How can I get a photo of a user with an acceptable resolution that can be used in a mobile application? I looked at the manuals and api docs, and it is recommended to use FirebaseUser # getPhotoUrl () . This, however, returns the URL of the photo with a resolution of 50x50 px, which is too small to be useful. Is there a way for a client to request a higher resolution photo of the user? I tested the sdks of logging into Facebook and logging into Google separately, and in both cases the resolution of the photos is higher than Firebase Auth returns. Why is Firebase Auth changing its original permissions and how can I make it not do this? Thanks.

+7
android firebase firebase-authentication
source share
3 answers

Inside onAuthStateChanged (@NonNull FirebaseAuth firebaseAuth)

Try it if you are logging in with Facebook:

if (!user.getProviderData().isEmpty() && user.getProviderData().size() > 1) String URL = "https://graph.facebook.com/" + user.getProviderData().get(1).getUid() + "/picture?type=large"; 
+6
source share

Facebook and Google PhotoURL:

  User myUserDetails = new User(); myUserDetails.name = firebaseAuth.getCurrentUser().getDisplayName(); myUserDetails.email = firebaseAuth.getCurrentUser().getEmail(); String photoUrl = firebaseAuth.getCurrentUser().getPhotoUrl().toString(); for (UserInfo profile : firebaseAuth.getCurrentUser().getProviderData()) { System.out.println(profile.getProviderId()); // check if the provider id matches "facebook.com" if (profile.getProviderId().equals("facebook.com")) { String facebookUserId = profile.getUid(); myUserDetails.sigin_provider = profile.getProviderId(); // construct the URL to the profile picture, with a custom height // alternatively, use '?type=small|medium|large' instead of ?height= photoUrl = "https://graph.facebook.com/" + facebookUserId + "/picture?height=500"; } else if (profile.getProviderId().equals("google.com")) { myUserDetails.sigin_provider = profile.getProviderId(); ((HomeActivity) getActivity()).loadGoogleUserDetails(); } } myUserDetails.profile_picture = photoUrl; private static final int RC_SIGN_IN = 8888; public void loadGoogleUserDetails() { try { // Configure sign-in to request the user ID, email address, and basic profile. ID and // basic profile are included in DEFAULT_SIGN_IN. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .build(); // Build a GoogleApiClient with access to GoogleSignIn.API and the options above. mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { System.out.println("onConnectionFailed"); } }) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); startActivityForResult(signInIntent, RC_SIGN_IN); } catch (Exception e) { e.printStackTrace(); } } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from // GoogleSignInApi.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); if (result.isSuccess()) { GoogleSignInAccount acct = result.getSignInAccount(); // Get account information String PhotoUrl = acct.getPhotoUrl().toString(); } } } 
+4
source share

You tried:

 Uri xx = FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl(); 
+1
source share

All Articles