B4J Question Understanding OAuth2

Brian Dean

Well-Known Member
Licensed User
Longtime User
My only real experience of net programming is writing a javascript/HTML4 website in 2003. I am trying to get a bit more up-to-date and am using @fredo 's excellent GoogleDrive example as a model, but in B4J rather than B4A.

I have installed Erel's OAuth2 class example and run it successfully in B4J. I have added fredo's [GoogleDrive] class and added the Google Drive API to my project in the Google console (at least I think so - how do I check?). The GoogleDrive class initialises successfully, but when I call a method (eg ShowFileList) I get this error -

"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."

How do I deal with this? It seems to mean that I am an authenticated user when I invoke the People API (it is working within the same app) but not when I use the GoogleDrive API, but that doesn't make sense to me.

Here is the relevant code from the GoogleDrive class :
B4X:
' I am calling this from Main with    GD.ShowFileList("")    where GD is an initialised GoogleDrive object.

Sub ShowFileList(ParentFolderID As String) As ResumableSub
    Dim h_sfl As HttpJob
    h_sfl.Initialize("", Me)
    If ParentFolderID = "" Then
        h_sfl.Download2("https://www.googleapis.com/drive/v3/files", _
             Array As String("access_token", myAccessToken, _
                             "corpora", "user", _
                             "q","mimeType!='application/vnd.google-apps.folder' and trashed=false"))
    Else
        h_sfl.Download2("https://www.googleapis.com/drive/v3/files", _
             Array As String("access_token", myAccessToken, _
                             "corpora", "user", _
                             "q", $"mimeType!='application/vnd.google-apps.folder' and '${ParentFolderID}' in parents and trashed=false"$))
    End If
    Wait For (h_sfl) JobDone(h_sfl As HttpJob)
    
    Log("h_sfl.Success=" & h_sfl.Success)
    If h_sfl.Success Then
        ....
        ....
    Else
'        Log("#-  x231, h_sfl.ErrorMessage=" &  h_sfl.ErrorMessage)
    End If
    h_sfl.Release
    Return Null   
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Seems like you added the peoples api to your google project but probably not google drive api.

Both needs to be set before you use any oAuth2 authentification.

I dont see any use of the OAuth2-Class in your code btw..
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I dont see any use of the OAuth2-Class in your code btw..
This is the call to OAuth2 ...
B4X:
    oauth2.Initialize(Me, "oauth2", ClientId, "profile email https://www.googleapis.com/auth/drive", _
        ClientSecret, File.DirData("TestBed1"))

Seems like you added the peoples api to your google project but probably not google drive api.
How can I check that? I am sure that once I found a way to show a list the APIs installed in a project, but I just cannot find it again.
 
Upvote 0
Top