Android Question Get Google Profile Stuff

mmieher

Active Member
Licensed User
Longtime User
I spent a bunch of time on this. I have something that works. Thought I would share to possibly save others pain.

I am sure that The Old Ones have much better methods, but my slogging has taught me a lot. I could not find much helpful information in the Forum.

Example: How to Get Authorized User's Google Primary Email Address and Profile Photo

First, get this $*@!ing thing. GoogleOAuth2 Token: ya29.A0ARrdaM-SAQocZrB...
See https://www.b4x.com/android/forum/threads/class-b4x-google-oauth2.79426/#content

Then do something better than this:
B4X:
Private Sub AuthorizeGoogle As ResumableSub
    LogSub("AuthorizeGoogle")
    
    oauth2.Initialize(Me, "oauth2", GOOGLE_AUTH_CLIENTID, "profile email https://www.googleapis.com/auth/userinfo.profile")
    ''oauth2.ResetToken    '    DEBUG
    oauth2.GetAccessToken
    ''LogColor("BEFORE Wait For OAuth2_AccessTokenAvailable",Colors.Yellow)
    Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
    ''LogColor("OAuth2_AccessTokenAvailable:  Success = " & Success, Colors.Yellow)
    ''Log("Token = " & Token)
    If Success Then
        '    what am i supposed to do with this token?  I am thinking nothing?  I gotta a guy handling it.
        ''Dim tokenMap As Map = CreateMap("token":Token)
        ''File.WriteMap(DIR,"tokenMap",tokenMap)
    Else
        LogColor("OAuth2_AccessTokenAvailable FAIL",Colors.Red)
        oauth2.ResetToken
        Return False
    End If
    
    '    get PeopleAPI email address and cover photo ------------------------------------------------------
    
    Dim j As HttpJob
    j.Initialize("", Me)
    
    #if documentation
    
    '    unknown source
    full list of features available: person.addresses,person.age_ranges,person.biographies,person.birthdays,
        person.bragging_rights,person.cover_photos,person.email_addresses,person.events,person.genders,person.im_clients,
        person.interests,person.locales,person.memberships,person.metadata,person.names,person.nicknames,person.occupations,
        person.organizations,   person.phone_numbers,person.photos,person.relations,person.relationship_interests,
        person.relationship_statuses,person.residences,person.skills,person.taglines,person.urls
    
    '    how does this relate to anything above?
    '    https://googleapis.dev/nodejs/googleapis/latest/people/interfaces/Params$Resource$People$Get.html
        Required. A field mask to restrict which fields on the person are returned. Multiple fields can be specified by separating them with commas.
        Valid values are: * addresses * ageRanges * biographies * birthdays * calendarUrls * clientData * coverPhotos * emailAddresses * events * 
                            externalIds * genders * imClients * interests * locales * locations * memberships * metadata * miscKeywords * names * 
                            nicknames * occupations * organizations * phoneNumbers * photos * relations * sipAddresses * skills * urls * userDefined
    
    ''    this works but is lame -- can /?json be somewhere in the url?
    ''  ORIG j.Download2("https://people.googleapis.com/v1/people/me", Array As String("access_token", Token, "requestMask.includeField", "person.emailAddresses"))
    
    #end if
    
    Dim apiResource As String = "https://people.googleapis.com/v1/people/me"
    Dim params() As String = Array As String(    "access_token", Token, _
                                                "requestMask.includeField", "person.photos", _
                                                "requestMask.includeField", "person.email_addresses" )                                                
    j.Download2(apiResource, params)
    
    LogColor("Wait For people.googleapis.com", Colors.Yellow)
    Wait For (j) JobDone(j As HttpJob)
    LogColor("people.googleapis.com j.Success = " & j.Success,Colors.Yellow)
    
    If j.Success Then
        Log(j.GetString)
        
        Dim qMap As Map = mParsePeopleData(j.GetString)
        ''Log(" ParsePersonData(j.GetString): qMap.Size =  " & qMap.Size)
        
        Log(fnPerson & " -----------------------------------------")
        For i = 0 To qMap.Size - 1
            Log(qMap.GetKeyAt(i) & "   " & qMap.GetValueAt(i))
        Next
        
        If qMap.Size > 0 Then
            File.WriteMap(DIR,fnPerson,qMap)
        Else
            LogColor("ParsePeopleData:  qMap.Size = 0",Colors.Red)
            Return False
        End If
    Else
        LogColor("people.googleapis.com:  j.Success FALSE", Colors.Red)
        oauth2.ResetToken
        AuthorizeGoogle
    End If
    j.Release
    
    Return Success
    
End Sub

Private Sub mParsePeopleData (iJSON As String) As Map
    LogSub("mParsePeopleData: " & CRLF & iJSON)
    
    Dim parser As JSONParser
    parser.Initialize(iJSON)
    Dim jRoot As Map = parser.NextObject
    
    Dim xMap As Map
    xMap.Initialize
    
    Dim emailAddresses As List = jRoot.Get("emailAddresses")
    For Each emlMap As Map In emailAddresses
        Dim metadata As Map = emlMap.Get("metadata")
        Dim primary As String = metadata.Get("primary")
        If primary = "true" Then
            Dim verified As String = metadata.Get("verified")
            Dim emlSource As Map = metadata.Get("source")
            Dim emlId As String = emlSource.Get("id")
            Dim emlType As String = emlSource.Get("type")
            Dim value As String = emlMap.Get("value")
            Dim sourcePrimary As String = metadata.Get("sourcePrimary")
        End If
    Next
    Dim resourceName As String = jRoot.Get("resourceName")
    Dim etag As String = jRoot.Get("etag")

    xMap.Put("verified",verified)
    ''xMap.Put("emlSource",emlSource)    '    do not need
    xMap.Put("sourcePrimary",sourcePrimary)
    xMap.Put("emlid",emlId)
    xMap.Put("emlType",emlType)
    xMap.Put("value",value)
    xMap.Put("resourceName",resourceName)
    xMap.Put("etag",etag)

    Dim Photos As List = jRoot.Get("photos")
    For Each photoMap As Map In Photos
        Dim metadata As Map = photoMap.Get("metadata")
        Dim primary As String = metadata.Get("primary")
        If primary = "true" Then
            Dim phurl As String = photoMap.Get("url")
            Dim phsource As Map = metadata.Get("source")
            Dim phId As String = phsource.Get("id")
            Dim phType As String = phsource.Get("type")
        End If
    Next
    xMap.Put("phurl",phurl)
    xMap.Put("phID",phId)
    xMap.Put("phType",phType)
    
    Return xMap
    
End Sub
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
Both the photo and the primary email address are personal data according to the General Data Protection Regulation (GDPR). This is subject to the requirements that the person in question must freely give consent for its use and the person requesting it must be able to demonstrate the freely given consent. This means that this solution appears to be inconsistent with or incomplete with the GDPR legislation.
Privacy is seen as the right to be left alone. Wouldn't it be simpler to ask the user for his email address and upload a photo? Providing it equals implicit consent from that user.
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
Uh. Note the name of the sub. This all happens after consent from the abuser.

Also, who gives a flying f about the GDPR? Why would you provide a photo and email address to Google, IF YOU DO NOT WANT ANYONE ELSE TO EVER SEE IT?

Hugs and Kisses!
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
To answer your questions, from what Google now asks for posting or updating an app is that Google does take the privacy rules of the GDPR into account. And to use an Android smartphone without providing your email address is very difficult, but indeed, you can try to send a fake photo or cartoon. That and with your given hug is the reason I gave you reaction a like.

Passing your email address and photo to Google does not automatically mean that you have given permission for third parties to collect this personal data. It is still too early to say how Google will deal with this in its assessment of the app on offer. As long as you realize it's more than just checking or unchecking the right box to get your app on the Play Store.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…