App Inventor, API Access and Authentication

App Inventor - Gmail Gmail Interface

Note: Google was modernizing OAuth interactions in Native Apps for Better Usability and Security, which means, this solution to receive an access token via webview unfortunately does not work anymore starting from April 20, 2017.
Use the Mail extension instead...

This example uses the new Gmail REST API. In this example the user can get a list of his last 10 Gmail messages, pick a message to see the details and send a message. Issue 1889 is no issue anymore.

Update: I fixed a small issue concerning base64 encoding of the message to send. The message must be web-safe base64 encoded, for details see also here.

Authorization of the user is required on first start of the app (similar to the App Inventor - Fusiontable interface and the App Inventor - Google Drive interface). Alternatively if you store your refresh token inside the app, you can use the example without need to login to send or receive emails from a Gmail account, which could be created especially for your app!

1. Authenticate via OAuth 2.0

For your own app, first register your application as described here, to be able to use OAuth to access Google APIs. In "APIs", just enable the Gmail API instead.

Then use these blocks for the further basic steps of the OAuth process.

In the authorization process, I'm currently using the following scope:
See a list of available scopes here.

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


To use the example without login, then follow these steps

2. Gmail API Examples

Example: List Messages

Lists the messages in the user's mailbox. I restricted the list with the maxResults parameter to get only the last 10 messages.
You also could use the q parameter to return messages matching the specified query, for example "". In the example, a list of the message ids will be diplayed in a listpicker to pick a message.

Example: Get Message

Gets the specified message. Pick a message from the listpicker to see the details of the message.

Example: Send Message

Sends the specified message to the recipients in the To, Cc, and Bcc headers.

Further blocks used


The Gmail API offers loads of possibilities. However I think, we can't send messages with attachments from within App Inventor using the Gmail API, because App Inventor does not offer multipart upload. For sending emails with attachments or sending HTML formatted emails, see my Mail extension.


Tested successfully on Nexus 5 running Android 4.4.4.

Questions and Answers

Q1:I can get the list of my emails and read them, but I can't send anything. The error message is: "page not found". Have you had any idea of what could it be? Or how can I fix it?
A: As I mentioned here I did not convert = into a websafe format. You can try to modify the webSafeBase64 procedure in Screen2 and additionally convert = to *.

Feedback from user: I had to put a space after the email to send correctly. Other thing I modified the webSafeBase64 procedure as you said and then the app works pretty well.

Back to top of page ...

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