B4J Question GoogleOAuth NonUI app

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am using GoogleOAuth2 with my B4J app (Non-UI).

Since my app is an nonUI app it can't open the web browser and authorize the app,wWhen using:

B4X:
Private Sub Authenticate
#if B4J
    PrepareServer
#End If
    Dim link As String = BuildLink("https://accounts.google.com/o/oauth2/v2/auth", _
         CreateMap("client_id": mClientId, _
        "redirect_uri": GetRedirectUri, _
        "response_type": "code", "scope": mScope))
       
#if B4A
    Dim pi As PhoneIntents
    StartActivity(pi.OpenBrowser(link))
#else if B4i
    Main.App.OpenURL(link)
#else if B4J
    fx.ShowExternalDocument(link)
#end if
End Sub

It says it can't use the JFX since that lib is not available as non-UI app. Which I understand.

Question I have is, how can I use this in a non-UI app?

I removed fx.ShowExternalDocument(link) from the code and it allowed me to run the app.

When I try and run it, it then comes up saying:

Getting access token from refresh token...
{
"error": "unsupported_grant_type",
"error_description": "Invalid grant_type: "
}
Error accessing account.

I am guessing it needs to issue a new token. However since this is a nonUI app it can't open the web browser to authorize the token.

Is there a way around this ?
 
Top