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:
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