Setting up the Gmail API

To use the Gmail API, you need to first create a Gmail account or have one already. The Gmail API uses OAuth2 authentication with Tokens. You need to go through the following steps to obtain the necessary tokens unless you already have them.

Creating the Client ID and Client Secret

  1. Navigate to API Credentials Page and sign in with your Google account.

  2. Click on Select a Project and click NEW PROJECT, to create a project. Creating a new Project

  3. Enter GmailConnector as the name of the project and click Create.

  4. Click Configure consent screen in the next screen. Consent Screen

  5. Provide the Application Name as GmailConnector in the Consent Screen. Consent Screen

  6. Click Create credentials and click OAuth client ID. Create Credentials

  7. Enter the following details in the Create OAuth client ID screen and click Create.

Type Name
Application type Web Application
Name GmailConnector
Authorized redirect URIs https://developers.google.com/oauthplayground
  1. A Client ID and a Client Secret are provided. Keep them saved. Credentials

  2. Click Library on the side menu, search for Gmail API and click on it.

  3. Click Enable to enable the Gmail API.

Obtaining Access Token and Refresh Token

  1. Navigate to OAuth 2.0 Playground and click OAuth 2.0 Configuration button in the Right top corner.

  2. Select Use your own OAuth credentials, and provide the obtained Client ID and Client Secret values as above click on Close. Obtaining Oauth-configuration

  3. Under Step 1, select Gmail API v1 from the list of APIs, select all the scopes except the gmail.metadata scope.

Selecting Scopes

  1. Click on Authorize APIs button and select your Gmail account when you are asked and allow the scopes. Grant Permission

  2. Under Step 2, click Exchange authorization code for tokens to generate an display the Access Token and Refresh Token. Now we are done with configuring the Gmail API. etting Tokens

Top