A two-minute primer to configure your Google account and Google Sheets to enable writing the results of the Python scripts with server-side authentication
To set up a service account and download a credentials file, follow these instructions (steps 1-6 are shown in the gif below):
- Go to the Google APIs Console (see first gif below for steps 1-6)
- Create a new project
- Click Enable API, then search for and enable the Google Sheets API
- Create credentials for a Web Server to access Application Data
- Name the service account and grant it a Project Role of Editor
- Download the JSON file (Caution! This can happen with little warning)
Configure config.ini
and the Google Sheet to know about the credentials file and the email address inside it
- Copy the JSON file to the same folder as your Python script and refer to it by name from config.ini as the GOOGLE_CREDENTIALS_FILE variable
- While you're there, also write the Google Sheets spreadsheet key to config.ini as the GOOGLE_SPREADSHEET_KEY variable. Get it from the URL of the Google Sheet. Example: https://docs.google.com/spreadsheets/d/**16VZFD8XNWbc2mjnzj4jbYiRf3GCu-CDcAq4CVi4RXB0**/edit#gid=0
- Find the client_email inside the json file. Back in the Google Sheets spreadsheet that you want to write to, click the Share button in the top right, paste the client email into the People field to give it edit rights, and hit Send (see second gif below)
This borrows heavily from Greg Baugues's post on Twilio.com