Android : How to get larger profile pic from Facebook using FirebaseAuth?
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);
Get larger facebook image through firebase login
According to the Facebook documentation on Profile Picture, you should be able to specify the size by appending width
and height
to the url:
let photoUrl = profile.photoURL?.absoluteString + "?width=\(width)&height=\(height)"
or by specifying the type:
let photoUrl = profile.photoURL?.absoluteString + "?type=large"
Firebase login with facebook -how to get larger profile image -javascript
You have to get the facebook User id from the user providerData object:
https://graph.facebook.com/{{authFacebook.user.providerData[fbIndex].uid}}/picture?width=800
What is the best practice to retrieve Facebook user picture with Firebase in Swift?
I found out that Firebase's photoURL
is Facebook's Graph API URL: http://graph.facebook.com/user_id/picture
. So, to get other sizes, all I need to do is to append a query string like ?type=normal
to the photoURL
.
To use GraphRequest
, consider @jnpdx's suggestion:
Seems like you have at least a couple of options: 1) Use the
GraphRequest and don't set your User model until you get the result
back. 2) Set your User model as you are now and then update it with a
new URL once your GraphRequest comes back.
Facebook Profile Picture Link Changes?
So somehow I finally figured this out today. Essentially the graphAPI spits back several pieces with one being a picture piece. This looks like the links I posted above https://platform-lookaside.fbsbx.com/platform/profilepic
THIS CHANGES!!! Not sure how often, but do NOT use this as eventually it will be a dead link.
However, what I missed was that you can use the ID that the graphAPI spits back instead and use the following link:
http://graph.facebook.com/{your_id_goes_here}/picture?type=large&redirect=true&width=500&height=500
More information can be found in this other post:
Get user profile picture by Id
Related Topics
How to Instantiate a Storyboard from a File Within an iOS Playground
Can a Swift Property Wrapper Reference the Owner of the Property Its Wrapping
Uitesting Xcode 7: How to Tell If Xcuielement Is Visible
Swift Lazy Subscript Ignores Filter
Creating a Custom Scngeometry Polygon Plane with Scngeometryprimitivetype Polygon Crash/Error
Is String Type a Class or a Struct? or Something Else
Iterating with for .. in on a Changing Collection
Clgeocoder in Swift - Unable to Return String When Using Reversegeocodelocation
Peak Detection for Growing Time Series Using Swift
Example of Dispatch_Once in Swift
Failed to Get Descriptors for Extensionbundleid
Understanding the Removerange(_:) Documentation
Navigationview Doesn't Display Correctly When Using Tabview in Swiftui
How to Nskeyedunarchiver.Unarchiveobject
Swift Package Manager - Type 'Bundle' Has No Member "Module" Error