Android Question OAuth2 - Stays in Browser and does not return processing to application

adriano.freitas

Active Member
I am a beginner in B4A programming. I'm trying to do a login via OAuth2 and with that get the user's access email so that I can identify it in a database. Searching the forum I found an example. I went to the google APIs console and did all access clearance procedures. When running, it seems to work. It opens the browser and lets you choose the account, requesting permission, however, then it goes to the browser's home page and does not return to the application or display the data (which by the example should be displayed). Can someone help me please?

B4X:
Sub BtnTeste_Click
    OAuth2.GetAccessToken
    Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
    If Success = False Then
        MsgboxAsync("Erro ao Tentar Acessar","Teste")
        Return
    End If
    Dim j As HttpJob
    j.Initialize("", Me)
    '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
    j.Download2("https://people.googleapis.com/v1/people/me", _
         Array As String("access_token", Token, "requestMask.includeField", "person.email_addresses,person.birthdays,person.names"))
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        ParsePersonData(j.GetString)
    Else
        OAuth2.ResetToken
        ToastMessageShow("Online data not available.", True)
    End If
    j.Release
End Sub

Sub ParsePersonData (data As String)
    Dim jp As JSONParser
    jp.Initialize(data)
    Dim map As Map = jp.NextObject
    Dim names As List = map.Get("names")
    If names.Size > 0 Then
        Dim name As Map = names.Get(0)
        MsgboxAsync(name.Get("displayName"),"Teste")
    End If
    Dim birthdays As List = map.Get("birthdays")
    If birthdays.Size > 0 Then
        Dim b As Map = birthdays.Get(0)
        b = b.Get("date")
        MsgboxAsync( $"$2{b.Get("day")}/$2{b.Get("month")}"$,"Teste")
    End If
    Dim emails As List = map.Get("emailAddresses")
    If emails.Size > 0 Then
        Dim email As Map = emails.Get(0)
        MsgboxAsync( email.Get("value"),"Teste")
    End If
End Sub
 
Top