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

问题描述

我一步一步地跟着 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)

标签: pythongoogle-sheets-apigspread

解决方案


我找到了答案!2 小时后,TechWithTim 视频中的范围对我不起作用,所以如果您遇到同样的问题,请尝试使用这个

scope = [
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive'
]

它是默认范围。


推荐阅读