App Inventor, API Access and Authentication

How to identify your user with OAuth OAuth

Note: with the extension feature, this workaround is now obsolete. Thank you MIT!
Now you can use my Account Manager Extension instead.

For the demo app I followed the simple example and the documentation Using OAuth 2.0 for Installed Applications.
In the example the user can authorize the app to read some user profile info. The following scope parameter are used in the example:

In case you like to identify your user in your app, you can use this example with the scope only, to get the user's email address for identification.

For questions about App Inventor,
please ask in the App Inventor community.Thank you.


First Run of the App

JSON Result

These information will be supplied in JSON format:

All further Runs of the App

The email, name and link to the picture of the user are stored in TinyDB and will then be displayed directly.

App Inventor Source

Preparation for your own app

Login to Google and register your application in the API Console to get a client id and client secret, see screenshot:

Questions and Answers

Q1: Will this code work in appinventor during application building or does the application need be packaged to test?
A: This example works during development and after packaging the app.

Q2:Users have to login on first run of the app to authorize the app. I was wondering if it is possible to automate and skip this process (so that users will not be directed to Google if the API key was created with a SHA1 signing certificate fingerprint by setting the installed application type to Android instead of other as you have prescribed?
A: If you finished your app, you can create a SHA1 signing certificate fingerprint. This restricts the access with the same client id and secret to your app, see also step 5 of this more detailled description. And I also recommend you to do that. However the user always needs to authorize your app to be able to read the user's info. This is how OAuth works. See also the Google documentation about OAuth: User login is clearly an essential part of most Google API access, but Google's authentication system can be used by your application as a stand-alone component. In other words, you can outsource user authentication and profile acquisition to Google. This is what we are doing: we outsource the user authentication to Google.

Q3: Is it possible for the user to logout from the apps, since when I tested this app, I don't need to re login to enter after exiting the app.
A: This is not a login example, it's an example to identify your user. And after the user is successfully identified, there is no need to unlog again. A user can manage the apps, which have been approved to connect to his account at in the Connected apps & sites tab. For a login example see here A login template by eiXerITS.


Tested successfully on HTC Desire running Android 2.2, Samsung Galaxy Tab 10.1N running Android 3.2 and Nexus 5 running Android 4.2.2.

Back to top of page ...

Home | Snippets | Tutorials | Extensions | Links | Search | Privacy Policy | Contact