Skip to content

Instantly share code, notes, and snippets.

@linuxkathirvel
Last active October 7, 2020 17:36
Show Gist options
  • Save linuxkathirvel/8df343be31c1d13b5913967783e44ed1 to your computer and use it in GitHub Desktop.
Save linuxkathirvel/8df343be31c1d13b5913967783e44ed1 to your computer and use it in GitHub Desktop.
How to read and update Google Sheet using Python without OAuth?

Create a Credentials object from the service account's credentials and the scopes your application needs access to.

https://developers.google.com/identity/protocols/oauth2/service-account#authorizingrequests

from google.oauth2 import service_account

SCOPES = ['https://www.googleapis.com/auth/sqlservice.admin']
SERVICE_ACCOUNT_FILE = '/path/to/service.json'

credentials = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE, scopes=SCOPES)

In Google Sheets how to reference infinite rows in column?

SAMPLE_RANGE_NAME = 'Sheet1!A:Z'
# You can use A:AA, A:AB and so on...

How to list files in a specific folder in Google Drive API v3 PHP

https://stackoverflow.com/questions/42055679/how-to-list-files-in-a-specific-folder-in-google-drive-api-v3-php

Reference and documentation

https://github.com/googleapis/google-api-python-client

@linuxkathirvel
Copy link
Author

How to solve this error?

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://sheets.googleapis.com/v4/spreadsheets/ returned "The caller does not have permission">

Solution

Share the sheet permission with 'Service Accounts's' email.

@linuxkathirvel
Copy link
Author

How to solve this error?

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/" Unable to parse range: Class Data!A2:E">

Solution

The sheet name 'Class Data' is not found in the sheet. Check the Sheet name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment