【发布时间】: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 包括步骤:
-
转到 Google API 控制台。
-
创建一个新项目。
-
单击启用 API。搜索并启用 Google Drive API。
-
为 Web 服务器创建凭据以访问应用程序数据。
-
为服务帐户命名并授予它编辑者的项目角色。
-
下载 JSON 文件。
-
将 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