1

I was trying to access my spreadsheet GetHookedTest from python following this tutorial. I've added service account successfully and here is my credentials. Shared by sheet with test@gethooked.iam.gserviceaccount.com

{
  "type": "service_account",
  "project_id": "gethooked",
  "private_key_id": "aaaaaabbbbbaaaabbbbaaaaa",
  "private_key": "Private Key here",
  "client_email": "test@gethooked.iam.gserviceaccount.com",
  "client_id": "454454554",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/orderplacer%test.iam.gserviceaccount.com"
}

import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pprint

scope = ["https://spreadsheets.google.com/feeds",
         'https://www.googleapis.com/auth/spreasheets',
         "https://www.googleapis.com/auth/drive.file",
         "https://www.googleapis.com/auth/drive"]

creds = ServiceAccountCredentials.from_json_keyfile_name("client_secret.json", scope)
client = gspread.authorize(creds)
sheet = client.open("GetHookedTest").sheet1

But I'm getting the RefreshError

six.raise_from(new_exc, caught_exc)
  File "<string>", line 3, in raise_from
google.auth.exceptions.RefreshError: ('No access token in response.', {'id_token': 'long string'})

Shahrear Bin Amin
  • 1,075
  • 13
  • 31
  • For example, when the scopes of `https://spreadsheets.google.com/feeds` and `https://www.googleapis.com/auth/drive.file` are removed and `client.open_by_key("SpreadsheetId").sheet1` is used instead of `client.open("GetHookedTest").sheet1`, what result will you get? – Tanaike Aug 31 '20 at 02:09
  • 1
    @Tanaike thank you it worked also had a typo in `spreadsheets` – Shahrear Bin Amin Aug 31 '20 at 03:14
  • Thank you for replying. I didn't notice it. But I'm glad your issue was resolved. If your issue was resolved, can you post it as an answer? By this, it will be useful for other users who have the same issue. – Tanaike Aug 31 '20 at 03:16
  • Thanks. I post it as an answer. Could you please confirm it? – Tanaike Aug 31 '20 at 03:19

1 Answers1

2

As one method, please try the following modification.

  1. Remove the scopes of https://spreadsheets.google.com/feeds and https://www.googleapis.com/auth/drive.file.

  2. Use the Spreadsheet ID instead of Spreadsheet name.

    • From

        client.open("GetHookedTest").sheet1
      
    • To

        client.open_by_key("SpreadsheetId").sheet1
      

Note:

  • From your reply comment, https://www.googleapis.com/auth/spreasheets is https://www.googleapis.com/auth/spreadsheets.
Tanaike
  • 181,128
  • 11
  • 97
  • 165