Android Question [FirebaseAuth] CurrentUser.PhotoUrl return 404.

zolive33

Active Member
Licensed User
Longtime User
Hello,

Since few days, the Method PhotoUrl returns an error code 404.

Code example :
B4X:
        Dim FBAuth As FirebaseAuth
        FBAuth.Initialize("")
        wbPhoto.Color=Colors.Transparent
        wbPhoto.LoadHtml("<html><body><img style=""position:absolute; border-radius:5px; left:0px; top:0px; width:100%; height:100%;"" src='" & FBAuth.CurrentUser.PhotoUrl & "'/></body></html>")

In my example, FBAuth.CurrentUser.PhotoUrl returns https://lh3.googleusercontent.com/-...V0G9pQ0gQXSwzTlAUDMJfHiaATzjw/s96-c/photo.jpg

Is it a Firebase bug?

Thank you for your help.
 

zolive33

Active Member
Licensed User
Longtime User
Hi,

Here's a solution to update Firebase profile from Google profile.

B4X:
Sub updateFbProfile()
   
    Dim tmpGoogleDisplayName As String = ""
    Dim tmpGooglePhotoUrl As String = ""
   
    Try
        'Retrieve user's public Google profile
        Dim jo As JavaObject = FBAuth.CurrentUser
        Dim sProviderData As List = jo.RunMethod("getProviderData", Null)
        For Each item In sProviderData
            Dim jo2 As JavaObject = item
            If jo2.RunMethod("getProviderId", Null) == "google.com" Then
                'données du profil Google
                tmpGoogleDisplayName = jo2.RunMethod("getDisplayName", Null)
                tmpGooglePhotoUrl =  jo2.RunMethod("getPhotoUrl", Null)
            End If
        Next
    Catch
        'exit
        Return
    End Try
   
    'Updates the FB profile if necessary
    If (tmpGoogleDisplayName <> "" And tmpGoogleDisplayName <> FBAuth.CurrentUser.DisplayName) _
    Or (tmpGooglePhotoUrl <> "" And tmpGooglePhotoUrl <> FBAuth.CurrentUser.PhotoUrl) Then
        Try
            Dim joUri As JavaObject
            Dim newPhotoUri As Object = joUri.InitializeStatic("android.net.Uri").RunMethodJO("parse",Array(tmpGooglePhotoUrl))
   
            Dim joBuilder As JavaObject
            joBuilder.InitializeNewInstance("com.google.firebase.auth.UserProfileChangeRequest.Builder", Null)
            joBuilder.RunMethodJO("setDisplayName", Array(tmpGoogleDisplayName))
            joBuilder.RunMethodJO("setPhotoUri", Array(newPhotoUri))
   
            Dim profileUpdates As Object = joBuilder.RunMethod("build", Null)
   
            Dim jo As JavaObject = FBAuth.CurrentUser
            Dim task As JavaObject = jo.RunMethod("updateProfile", Array(profileUpdates))
            Do While task.RunMethod("isComplete", Null) = False
                Sleep(100)
            Loop
   
            Log("Profile updates :-)")
        Catch
            'exit
            Return
        End Try
    End If
   
End Sub
 
Upvote 0
Top