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 https://www.googleapis.com/auth/userinfo.email scope
only, to get the user's email address for identification.
I can help you: for one hour I charge 25 USD.
Please contact me at info [at] puravidaapps [dot] com for details!
For questions about App Inventor, please use the App Inventor forum. Thank you.
These information will be supplied in JSON format:
The email, name and link to the picture of the user are stored in TinyDB and will then be displayed directly.
Login to Google and register your application in the API Console to get a client id and client secret, see screenshot:
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 myaccount.google.com 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.