The new Gmail API

By: Google Developers

328   10   84393

Uploaded on 06/25/2014

For ten years now, app developers have wanted to integrate Gmail features into their apps, and until now the only way to do so was to implement full IMAP. Starting this week, the new Gmail API gives RESTful access to the user's Gmail threads, labels and messages, and does so with high performance, APIary level control and SLAs and with SDK level access for client side developers. We'll show the API in action, highlight some 3party early adopters, and show how you can use it to power your apps.

Comments (4):

By anonymous    2017-09-20

On June 25, 2014 Google released new Gmail API that can be used to easily gather messages, threads, labels and more from Gmail accounts. Service is OAuth 2 protected. They provide nice client libraries for Python, .NET and Java and wonderful documentation for those doing RESTful implementation.

I suggest using their API instead of IMAP - because Gmail has and supports many features that were not designed to run over IMAP. Features like search, tagging, etc...

You can also check their YouTube video for a nicer introduction.

Original Thread

By anonymous    2017-09-20

(Feb 2017) The Gmail API (v1 launched Jun 2014) is the best way of integrating Gmail functionality into your apps (and preferred over POP/IMAP & SMTP). In order to use this and most other Google APIs from Android, you need to get the Google APIs Client Library for Android (or for more general Java, the Google APIs Client Library for Java).

Now for some working samples: here are the Android quickstart & the more general Java quickstart. Having the Gmail API JavaDocs reference at your side isn't a bad idea either. OAuth2 is now the preferred way to perform auth, meaning you'll need code that looks like this, plus the right scope:

// Sheets RO scope
private static final String[] SCOPES = {GmailScopes.GMAIL_READONLY};
    :

// Initialize credentials and service object
mCredential = GoogleAccountCredential.usingOAuth2(
        getApplicationContext(), Arrays.asList(SCOPES))
        .setBackOff(new ExponentialBackOff());

Other than this "setup," the OP has most everything needed to get something working:

  1. Having a project in the developers console & enabled the Gmail API with the SHA1 hash (as described above in the Android quickstart)
  2. Implementing OAuth2 with the correct scope(s)
  3. Making the call to ListThreadsResponse listResponse = mService.users().threads().list(user).execute(); -- the quickstart uses labels() so you can just change to threads()

To learn more about the API, below are 3 videos, the first introducing the API when it launched. If you're not "allergic" to Python, I made the other pair with short but more "real-world" examples using the Gmail API (non-mobile though):

It's not mentioned as part of the title, but the 2nd video above features a code sample that accesses thread and messages with the Gmail API.

Original Thread

Recommended Books

    Submit Your Video

    If you have some great dev videos to share, please fill out this form.