Android Question GoogleOauth2 refresh token

RAFA BRAVO

Active Member
Licensed User
Longtime User
Hello.
I use the Googleoauth2 class to send mail. Everything works fine, but when a week or so passes. the access token is not renewed and I get this error:

B4X:
Getting access token from refresh token...
ResponseError. Reason: , Response: {
  "error": "invalid_grant",
  "error_description": "Token has been expired or revoked."
 }
 Error accessing account.
 

RAFA BRAVO

Active Member
Licensed User
Longtime User
No, got refresh token, so i decided to try your simple example:
https://www.b4x.com/android/forum/threads/b4x-sending-emails-with-gmail-rest-api.81736/#content
This example works well for me, so I rule out an erroneous configuration in the google console API.
My project has some changes, I use B4XPages, i use this:
https://www.b4x.com/android/forum/threads/google-oauth2-b4xpages-callfromresume.137078/
in the module B4XMainPage:
B4X:
Sub Class_Globals
    Public oauth2 As GoogleOAuth2
    Public ClientId As String = "*****"
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
   
    oauth2.Initialize(Me, "oauth2", ClientId, "https://www.googleapis.com/auth/gmail.send")
       
End Sub

Private Sub B4XPage_Foreground
    oauth2.CallFromResume(B4XPages.GetNativeParent(Me).GetStartingIntent)
End Sub

I also change the package name with this:
https://www.b4x.com/android/forum/threads/problem-sending-emails-with-gmail-rest-api.97182/
what am I doing wrong?, thanks
 
Last edited:
Upvote 0

RAFA BRAVO

Active Member
Licensed User
Longtime User
Rectified, I also haven't managed to refresh the token in this simple example:
https://www.b4x.com/android/forum/threads/b4x-sending-emails-with-gmail-rest-api.81736/#content
I think the error is in the google API console configuration. I create the project, enable the gmail API or service.
I create the credentials with the name, the package name of the APP and the SHA-1 fingerprint. in the consent screen, I have the project as external users and in tests. And with some test users added. Do I need to publish the APP for it to work? or it is not a problem for you to refresh the token. Thanks
 
Upvote 0

RAFA BRAVO

Active Member
Licensed User
Longtime User
I understand that this is how it should work, but I don't understand why my service only works for one week.
Believe that the configuration in the google api console is correct?
 
Upvote 0
Top