How to Create Credentials for Gmail API in Google Cloud Platform (GCP)

Credentials are used to obtain an access token from a Google authorization server. This token is used to call Google Workspace APIs. In this post, we will create Client Credentials for Gmail API.

Prerequisites

  1. GCP Account
  2. Enable Gmail API in GCP

Configure the OAuth consent screen

Open the Google Cloud Console. Select the Project.

On the left side menu, click on APIs & Services.

Inside the APIs & Services, click on Credentials.

This will open up Credential page for your project. Click on Configure Consent Screen.

Click the user type for your app. I will be selecting External because I am not a Google Workspace user. For more details on Setting up OAuth Consent Screen, refer to the Google documentation.

Fill out the form –

  1. App name: Give a descriptive name of your app.
  2. User support email: Select your personal email.
  3. Developer Contact Information: Give your personal email.

Leave the other fields blank on this form and click on Save and Continue. You will move to the Scopes. If you are creating an external app, click Add or Remove Scopes. Since I am using the Gmail API for sending messages only, I will go ahead and select the scope .../auth/gmail.send.

My selected scope has come under Sensitive scopes. Click on Save and Continue.

If any of the scopes are under Sensitive scopes and restricted scopes, your app will go through some assessment and verification. For more information, refer to the Google guides on Identity Scopes.

Save and Continue from the Test Users page.

The Summary page shows all the options and fields selected by you. Click on Back to Dashboard.

Create a OAuth client ID credential

On the left side menu of APIs & Services, click on Credentials.

Click on Create Credentials and select OAuth client ID.

Choose the type of the application you are building, I will select Web Application. Give a name of your client and click on Create.

Since I don’t have any JavaScript origins and redirect URI, I will leave blank. If your application has Redirect URI or JavaScript origins, enter it here. For more information on setting up OAuth, refer here.

Copy your client ID and client secret and keep it safe.

You can now download the client credentials JSON and use it in your application.

Thank you All!!! Hope you find this useful.


Up ↑

%d bloggers like this: