Setting Up a Project, Service Accounts and OAuth Credentials

Ivhani Maselesele
3 min readApr 18, 2020

We followed a tutorial by GREG BAUGUES’ on the Twilio website to set up a project and get access keys. We’ll copy most of the content from their website here.

Creating The Spreadsheet

  • Create a spreadsheet in your google drive — name it: email_notification
  • Create a sheet named addressess with columns: email address, full name
The incorrectly spelled “Addressess” sheet
  • Create a sheet named content with columns: subject, greeting, body, footer
The content sheet

Create and Get Access Credentials

To programmatically access your spreadsheet, you’ll need to create a service account and OAuth2 credentials from the Google API Console. If you’ve been traumatized by OAuth2 development before, don’t worry; service accounts are way easier to use.

Follow along with the steps and GIF below.

  1. Go to the Google APIs Console.
  2. Create a new project.
  3. Click Enable API. Search for and enable the Google Drive API.
  4. We ran into permission issues and had to enable the Google Sheets API, so we’ve added an extra step: Search for and enable the Google Sheets API.
  5. Create credentials for a Web Server to access Application Data.
  6. Name the service account and grant it a Project Role of Editor.
  7. Download the JSON file.
  8. Copy the JSON file to your code directory and rename it to client_secret.json

There is one last required step to authorize your app, and it’s easy to miss!

Share The Spreadsheet

Find the client_email inside client_secret.json. Back in your spreadsheet, click the Share button in the top right, and paste the client email into the People field to give it edit rights. Hit Send.

If you skip this step, you’ll get a gspread.exceptions.SpreadsheetNotFound error when you try to access the spreadsheet from Python.

If you prefer watching a video instead, the video below does the exact same thing.

Congratulations once again, you’ve created a spreadsheet and service account credentials we’ll use to programmatically access the spreadsheet.

In the next section, we’ll integrate Google Sheets to extract mail contents and email addresses. Click here to go to the next section.

This is tutorial is broken up into 5 parts:

--

--