如何修复“google.auth.exceptions.RefreshError: ('No access token in response.” 尝试使用 GoogleSheet API 打开电子表格时

Tir*_*rra 2 python gspread google-sheets-api

我一步一步地关注了 TechWithTim 的视频 ( https://www.youtube.com/watch?v=cnPlKLEGR7E ),但是当我尝试打开工作表时仍然出现错误。代码工作正常,直到sheet = client.open("GuildTaxes").sheet1行。这是我的代码。

import gspread
from oauth2client.service_account import ServiceAccountCredentials

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

creds = ServiceAccountCredentials.from_json_keyfile_name("GuildTaxes-9ba4508be840.json", scope)

client = gspread.authorize(creds)

sheet = client.open("GuildTaxes").sheet1

data = sheet.get_all_records()

print(data)
Run Code Online (Sandbox Code Playgroud)

Tir*_*rra 5

我找到了答案! 2 小时后,TechWithTim 视频中的范围对我不起作用,因此如果您在同一问题上发茬,请尝试使用此范围

scope = [
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive'
]
Run Code Online (Sandbox Code Playgroud)

它是默认范围。