Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I am using FirebaseAuth to login 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 issue is that the photo in I get from using user.getPhotoUrl() is very small. I need a larger image and can't find a way to do that. Any help would be highly appreciated. I have already tried this Get larger facebook image through firebase login but it's not working although they are for swift I don't think the API should differ.

like image 552
Gaurav Sarma Avatar asked Aug 23 '16 07:08

Gaurav Sarma


People also ask

How do I choose my profile picture on Facebook from my gallery?

Tap in the top right of Facebook, then tap your name. Tap your profile picture. Choose to Take Photo, Upload Photo, Add Frame or View Profile Picture. Tap Save.


1 Answers

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); 
like image 110
mfb Avatar answered Sep 24 '22 10:09

mfb