🟦 Google Drive Connector (GDC): Connect an AI2 app to the user’s Google Drive

As you may know, I have, along with many others, both before and after me, developed different methods and opportunities to connect AI2 to "Google things", in the main; Drive and Sheets. The one sticking point with this has always been that the Drive or Sheets in question are always "owned" by the app developer.

The issue with using google apps script to create a web app, in order to connect things up, is that it requires a "proper" web browser for the user to authenticate, and also in an unverified state, presents some unpalatable dialogs and warnings to the user.

Because the google web app must be run as "the user who accesses the app", in order for the user to access their own account and google drive, it is not possible to use 0Auth2 libraries to run with the web component, or keep things inside the app, and also the fact that the native webview will not handle the web app authentication due to Google's changes in this area a couple of years ago. However, it is possible to authenticate the web app (give permission) using the device browser (e.g. Chrome), then use the native webviewer to carry out the GET requests, once signed in to Google.

I created a web app that required the "restricted" scopes for Drive/Sheets/Documents/Slides, and submitted it for verification by Google. It came back verified after 24 hours (they say 4-6 weeks is normal). This now means that although authentication is still required, it is a slightly more pleasing process for the end user of an app. As a part of the verification process, I have created a product page and privacy policy for end users and app developers. I have also created a demo app that shows the authentication process and how the web app works.

I believe that this has got "legs", will be of use to many AI2 developers, and can think of many reasons for end users to feel more comfortable, or to find things more practical, to have their data on their Google Drive/Sheet etc.

Provided directly is a DEMO APP for you to try which offers a few of the 26 available functions (to date). I strongly recommend you read the documentation (which is also available in the app itself). When testing the demo app, it is best to have your google drive open on a computer, in order that you can observe the changes. (the best bit!)

A full version apk (all functions so far) is available upon request through registration. Interested developers can also register for a base aia and the web app link in order that they can develop their own applications. Registration with me is required in order that I can provide support, assistance and upgrades. I cannot “open source” everything, given the inherent authentication requirements put in place by Google, but for those that wish to create their own web app, I will be happy to show them how it was done.

DEMO APP (apk)

DOCUMENTATION/WEBSITE

DIRECT LINK TO REGISTRATION FORM

My thanks go out to @GC1, @Taifun, @DanHG & @HarryGC for beta testing along the way.

No extensions were required for the authentication process, however I did use @vknow360’s FileTools and Filey extensions to improve the use of the various functions (file picking and base64 conversion). Thank you, Sunny, for your work. Accreditation also to MIT App Inventor for the kodi “bee” logo, used in my logo.

Note: in testing, I have observed (so far...) three different behaviours from Chrome/Google when initially authenticating the google web app(GDConnector):

  1. As seen in my phone/emulators and shown on the website images
  2. Automatic authentication with no need for the user to login (although they have to login inside the app)
  3. When user not logged into their account in Google, once logged in, not need to log in again to complete authentication (although they have to login inside the app)

The android app is developed and tested in MIT App Inventor. It may work in other distributions.

13 Likes

When I want to get a list of files from disk or folders, I get "got list of root files" but I can't see my files list anywhere.

Pleased to here you got through the authentication process :slight_smile:

In the demo apk, you can see the file list if you select Download a File from the Read menu, then press Select File from List. You can cancel out after selecting if you do not want to download.

File saving to the root of the sdcard is working OK on my Android 10 emulator.....(I put all this together before all the file storage mess caused by Google)

The authorization process is quite complicated :).
I went through GooglePlay a bit. For example, I found the NE Google Drive application. There, authorization is obtained with two clicks. Can't such authorization be obtained in AppInventor?

I have explained all this in the documentation.

Maybe one of the browsers from the extensions will allow you to obtain authorization?

Nope. Even when changing user agents, Google "knows" it is a webview and will not allow a user to authenticate. Believe me, I tried everything :wink:

So how do other applications get authorization in their own window without opening chrome? For example, the one mentioned above?

They will be using the android specific methods for authentication for Google Drive (0Auth).
Regardless, at some point the user will be required to authenticate with the web app (required by GDC to perform all the functions in GDC) - at that point they would need to go out to a native browser.

1 Like

I downloaded the demo apk - click on setup - clicked on sign ( I signed in with my account ) - click on auth- clicked on review permission and then this error occurred.

I think this can be solved by using custom webview extension by @vknow360 and changing user agent.

You can give it a try.

Which Android version are you using?

Xiaomi MI A3 - Android 11

OK, GDC put together before Android 11, this could be the issue. I'll need to work through the code.

1 Like

Working in my phone running on Android 11.

Thanks for testing Sunny :slightly_smiling_face:

Are you still stuck, or is everything working OK now?

Nope I am getting the same error from the demo apk.

Maybe the problem is device specific and can be solved by using a valid user agent.