How do I rename a (work)sheet in a Google Sheets spreadsheet using the API in Python?

This is an extraction of a library which I’ve coded personally: def _batch(self, requests): body = { ‘requests’: requests } return self._service.spreadsheets().batchUpdate(spreadsheetId=self.spreadsheetId, body=body).execute() def renameSheet(self, sheetId, newName): return self._batch({ “updateSheetProperties”: { “properties”: { “sheetId”: sheetId, “title”: newName, }, “fields”: “title”, } }) I think that with a little effort, you can implement it into your … Read more

How can I get a list of sheets (name and “gid”) in a Google spreadsheet using the Drive API?

You can use an old visualization API URL f’https://docs.google.com/spreadsheets/d/{doc_id}/gviz/tq?tqx=out:csv&sheet={sheet_name}’ to download a sheet by its name. I just posted this here together with code for the Google API Python library. This is also mentioned in another answer which links to the Charts docs where it is shown how to do this with a gid. Alternatively, … Read more

ValueError: Client secrets must be for a web or installed app

For anyone coming here because they would like to actually connect to the GCP calendar API via a service-account and not this Oauth2 client id, create the creds object in the original example as follows: from google.oauth2 import service_account SCOPES = [‘https://www.googleapis.com/auth/calendar.readonly’] SERVICE_ACCOUNT_FILE = ‘/path/to/service.json’ credentials = service_account.Credentials.from_service_account_file( SERVICE_ACCOUNT_FILE, scopes=SCOPES) Assuming the service-account is configured … Read more

How do I access (read, write) Google Sheets spreadsheets with Python?

(Jun-Dec 2016) Most answers here are now out-of-date as: 1) GData APIs are the previous generation of Google APIs, and that’s why it was hard for @Josh Brown to find that old GData Docs API documentation. While not all GData APIs have been deprecated, all newer Google APIs do not use the Google Data protocol; … Read more

tech