Not able to fetch Facebook profile image using Firebase Authentication

98 Views Asked by At

I am working on a project in which I have integrated Facebook login using Firebase authentication. I am fetching the public profile picture. However my code is not able to do this task. Please try to fix this.

Here is the small part of the code I used

private fun handleFacebookAccessToken(token: AccessToken) {
        val credential = FacebookAuthProvider.getCredential(token.token)
        auth.signInWithCredential(credential)
            .addOnCompleteListener(this) { task ->
                if (task.isSuccessful) {
                    val user = auth.currentUser
                    val photoUrl = "${user.photoUrl}?access_token=${token.token}"

Here I get not image

private fun handleFacebookAccessToken(token: AccessToken) {
        val credential = FacebookAuthProvider.getCredential(token.token)
        auth.signInWithCredential(credential)
            .addOnCompleteListener(this) { task ->
                if (task.isSuccessful) {
                    val user = auth.currentUser
                    val photoUrl = user.photoUrl.toString()

When I used the following code, I am getting the default Facebook profile photo: image which is shown

Note: In XML file I am using the default Image View, not Facebook profile view attribute

1

There are 1 best solutions below

1
Hezy Ziv On
user?.let {
                        val facebookUserId = it.providerData[1].uid
                        val photoUrl = "https://graph.facebook.com/$facebookUserId/picture?type=large"

                }