【问题标题】:"No access token in response" error, while trying to access to Google Sheet尝试访问 Google 表格时出现“没有响应的访问令牌”错误
【发布时间】:2021-01-26 16:42:08
【问题描述】:

我尝试通过 Python 使用 Google Sheet

按照本网站的指导: https://www.twilio.com/blog/2017/02/an-easy-way-to-read-and-write-to-a-google-spreadsheet-in-python.html 包括步骤:

  1. 转到 Google API 控制台。

  2. 创建一个新项目。

  3. 单击启用 API。搜索并启用 Google Drive API。

  4. 为 Web 服务器创建凭据以访问应用程序数据。

  5. 为服务帐户命名并授予它编辑者的项目角色。

  6. 下载 JSON 文件。

  7. 将 JSON 文件复制到您的代码目录并将其重命名为 client_secret.json

这是我到目前为止所做的

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

但是,我得到了这个结果错误

google.auth.exceptions.RefreshError: ('没有访问令牌响应。', {'id_token'..}

【问题讨论】:

    标签: python google-drive-api google-api-python-client gspread


    【解决方案1】:

    我在使用教程中的范围时遇到了同样的错误,所以我尝试了 DaImTo 建议的 scopes#sheets 中的几个,直到它最终起作用。 对我来说是scope = ['https://www.googleapis.com/auth/drive']

    【讨论】:

      【解决方案2】:

      那不是谷歌范围。这是有效的谷歌列表scopes#sheets

      即使您正在遵循的教程也说要使用以下范围。不包括您字体可以访问的正确 oauth 范围。

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

      【讨论】:

      • 我正在使用你所说的范围,但后来我得到了“gspread.exceptions.APIError(请求的身份验证范围不足)”。我在我的谷歌表格上向用户添加了 client_mail ......有什么想法吗?
      猜你喜欢
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 2015-12-08
      • 1970-01-01
      • 2021-11-07
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多