Search code examples
pythongoogle-drive-apigoogle-api-python-clientgspread

"No access token in response" error, while trying to access to Google Sheet


I trying to working with Google Sheet by using Python

Following the guidance from this site: https://www.twilio.com/blog/2017/02/an-easy-way-to-read-and-write-to-a-google-spreadsheet-in-python.html Including steps:

  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. Create credentials for a Web Server to access Application Data.

  5. Name the service account and grant it a Project Role of Editor.

  6. Download the JSON file.

  7. Copy the JSON file to your code directory and rename it to client_secret.json

Here is what I did so far

import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://docs.google.com/spreadsheets/d/1IypqDnLKKR-IX1oOwCuTejBQ-RFq87K9rqSF6GpSyn4/edit?usp=drive_web&ouid=109125393303568297837']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)
sheet = client.open('test_xlsx').sheet1

However, I got this result errors

google.auth.exceptions.RefreshError: ('No access token in response.', {'id_token'..}


Solution

  • Thats not a google scope. this is the list of valid google scopes#sheets

    Even the tutorial you are following says to use the following scope. Without including the correct oauth scope you font have access.

    scope = ['https://spreadsheets.google.com/feeds']