Android Question [SOLVED] [B4X] Google OAuth2, how to get and apply the profile photo

Cableguy

Expert
Licensed User
Longtime User
Hi guys,

I'm trying to get the avatar or profile photo, whatever you want to call it, using the OAuth2 class, but Not getting very far...
here's what I've tried, no luck.:
B4X:
    Dim avatar As Map = map.Get("cover_photos")
    If avatar.IsInitialized Then
        Dim my_avatar As Bitmap = avatar.Get(0)
        my_avatar.Initialize2(avatar.Get("value"))
        ImageView1.Bitmap = my_avatar
    End If
 

Cableguy

Expert
Licensed User
Longtime User
As usual, I keep searching, fiddling, tweaking, and eventually get to the solution on myself...
So, here you have, how to retrieve the profile photo using OAuth2.

B4X:
...............................................
    
    Dim avatar As List = map.Get("photos")
    If avatar.IsInitialized And avatar.Size > 0 Then
        Dim my_avatar As Map = avatar.Get(0)
        DownloadImage(my_avatar.Get("url"), ImageView1)
    End If

...............................................

Sub DownloadImage(Link As String, iv As ImageView)
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(Link)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        iv.Bitmap = j.GetBitmap
    End If
    j.Release
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…