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.
8
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.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 (96×96 in this case)so you just need to replace that value with the desired size.
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.
You can store this link to firebase database with user facebookId and use this in app.
Also you can change height as a parameter
Not for Android, but for iOS, but I thought it could be helpful for other people (I didn’t find a iOS version of this question).
Based the provided answers I created a Swift 4.0 extension that adds a function
urlForProfileImageFor(imageResolution:)
to the FirebaseUser
object. You can either ask for the standard thumbnail, a high resolution (I put this to 1024px but easily changed) or a custom resolution image. Enjoy:Two lines of code.
FirebaseUser user = firebaseAuth.getCurrentUser();
simply append
"?height=500"
at the endNote: From Graph API v8.0 you
must provide the access token
for every UserID request you do.Hitting the graph API:
With firebase:
You get the token from
registerCallback
just like thisThis is what documentation says:
I use this code in a Second Activity, after having already logged in, for me the Token that is obtained in
loginResult.getAccessToken().getToken();
It expires after a while, so researching I found this and it has served meCheck below response