Skip to content

Instantly share code, notes, and snippets.

@AnalyzePlatypus
Created May 19, 2020 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnalyzePlatypus/50baff0e593c13f18e617a2c0b370f2e to your computer and use it in GitHub Desktop.
Save AnalyzePlatypus/50baff0e593c13f18e617a2c0b370f2e to your computer and use it in GitHub Desktop.

Obtaining Gmail OAuth tokens

To access your Gmail account from the API, you will need to obtain the following values from Google's OAuth system:

clientId clientSecret refreshToken

Part 1: Client secrets

  1. Open console.google.com
  2. Click create new project. Name and create.
  3. Search for "Gmail API" and click Enable
  4. Visit the OAuth consent tabard populate the form
  5. Visit the Credentials tab and click "CCReate Credentials -> OAuth client ID"
  6. Select "Web Application"
  7. Under Authorized redirect URIs paste https://developers.google.com/oauthplayground (Without a trailing slash!)
  8. Copy the generated Client ID and Client Secret.

Part 2: Obtaining a Refresh Token

  1. Visit https://developers.google.com/oauthplayground
  2. Click on the gear icon to open the Configuration menu
  3. Check the checkbox "Use your own OAuth credentials"
  4. Paste in your Client ID and Client Secret. Close the panel.
  5. Under "Select and Authorize APIs" select Gmail API. (Or customize the scope of your auth, such as compose-only)
  6. Click Authorize APIs. Click through the Google login flow.
  7. When authorization is complete click Exchange authorization code for tokens
  8. Copy the Refresh Token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment