Android Question Updating Google Sheet --> stuck in oauth2.GetAccessToken

Javier Campo Martinez

Member
Licensed User
Hi guys !!!!
I'm trying to update a Google Spreadsheet, using OAuth2 library.

This is my piece of code:
B4X:
Sub Process_Globals
    Dim ClientId As String = "..."
    Private oauth2 As GoogleOAuth2
End Sub


Sub Activity_Create(FirstTime As Boolean)
    ...

    If FirstTime Then
        oauth2.Initialize(Me, "oauth2", ClientId, "https://www.googleapis.com/auth/spreadsheets")
    End If
    
..
End Sub

Sub SendDataToGoogleSpreadsheet
    Dim mylist As List
    mylist.Initialize
    Dim m As Map
   
    m.Initialize
    
    m.Put("Column1",MyColumn1Value)
    m.Put("Column2",MyColumn1Value)
    m.Put("Column3",MyColumn1Value)
    m.Put("Column4",MyColumn1Value)    
    
    Dim j As JSONGenerator
    j.Initialize2(mylist)
    
    Dim job As HttpJob
    job.Initialize("SendAssets", Me)
    Dim text1 As JSONGenerator
    text1.Initialize(m)
    Dim SS As String
    SS = text1.ToPrettyString(1)

    oauth2.GetAccessToken
    Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
    If Success = False Then
        ToastMessageShow("Error accessing account.", True)
        Return
    End If
    
    job.PostString("https://sheets.googleapis.com/v4/spreadsheets/<spreadsheetID>/values/Sheet1!A1:D1:append?valueInputOption=USER_ENTERED", SS)
    job.GetRequest.SetContentType("application/json")
    Wait For (job) JobDone(job As HttpJob)
    If job.Success = True  Then
        Log("Response Length:" & job.GetString.Length & " bytes")
        Log(job.GetString)
    
    End If
End Sub

The sentence oauth2.GetAccessToken prompts for the user to allow actions on the spreadsheet (edit, delete, ... ), after allowing those actions, it doesn't return to the app, instead of that the navigator is still showing. See images attached.

What other(s) action(s) do you consider are needed to send the data to the spreadsheet?

Thanks in advance, and best regards !!!
 

Attachments

  • APP1901.jpg
    APP1901.jpg
    58.3 KB · Views: 249
  • APP1903.jpg
    APP1903.jpg
    53.3 KB · Views: 242
  • APP1904.jpg
    APP1904.jpg
    47.3 KB · Views: 249

Javier Campo Martinez

Member
Licensed User
This is the relevant tutorial: [class][B4X] Google OAuth2

Make sure to add the required code in the manifest editor.

One question related to the manifest editor:
I suppose that, in the manifest, $PACKAGE$ = my application's package name. I.e. if my package name is com.myapp.jlcm, then the manifest would be:

B4X:
AddActivityText(Main,
  <intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data android:scheme="com.myapp.jlcm" />
  </intent-filter>
   )

Am i right?

Looking forward for your kind comments, and best regards!!!!
 
Upvote 0

Javier Campo Martinez

Member
Licensed User
Hello !!! what's up?

Thanks anyway for your interest. I cannot get OAuth2 to work for my needs (to insert data in a Google Sheet).

I made sure to read the OAuth2 post well, to compare line by line the example code ... the clientID ... the changes in manifest ... the initializations ... used the GoogleOAuth2.bas attached outside of the zip files ... anyway. I'm still stuck on these lines:
B4X:
    oauth2.GetAccessToken
    Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
which are still showing Google's homepage after "allowing" access to the spreadsheet. It doesn't return to the app.

I must be doing something wrong, but I don't know what and it is difficult to guess, which piss me off.

Best regards :)
 
Last edited:
Upvote 0

Dapesan

New Member
Have you solved this topic?

When I allow access sending an e-mail with Gmail return me to the Google's homepage and my program stops. I don't receive the access token but I don't have any error and I don't know how to find the problem
 
Upvote 0

Javier Campo Martinez

Member
Licensed User
Have you solved this topic?

When I allow access sending an e-mail with Gmail return me to the Google's homepage and my program stops. I don't receive the access token but I don't have any error and I don't know how to find the problem
Hi Dapesan.
I couldn't get the Google sheet access to work, the way it was indicated in Erel's tutorial. Apologies.
Finally, I purchased a host and sent the information to a database through HttpJob class. Another option is to use sheet.best (it works like a charm), only 5 bucks per month and it's easy to read/write/query any Google Sheet.
Best regards,
 
Upvote 0

Dapesan

New Member
Thanks. I finally have find the solution. My app have several activities and I have solved with this tutorial:


Maybe it can help you
 
Upvote 0

Javier Campo Martinez

Member
Licensed User
Thanks. I finally have find the solution. My app have several activities and I have solved with this tutorial:


Maybe it can help you
Thanx bro. I will take a look @ that , to see (in my case) if i can put OAuth2 to work.
 
Upvote 0
Top