使用Python访问Google Sheets Api

Kir*_*wty 8 python google-sheets-api

我目前正在尝试通过python更新Google表格,但遇到权限方面的一些问题。

我一直在遵循Twilio指南中的说明:https://www.twilio.com/blog/2017/02/an-easy-way-to-read-and-write-to-a-google-spreadsheet- in-python.html

我正在Jupyter中完成所有这些工作,并且确实将JSON文件保存到了正确的代码目录中。我没有定义范围,信誉和客户的问题。

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_id.json', scope)
client = gspread.authorize(creds)

sheet = client.open("MixIQ Tracker").sheet1
Run Code Online (Sandbox Code Playgroud)

我已经完成了链接两者的所有步骤,但是最后一行却出现了此API错误。

APIError: {
"error": {
  "errors": [{
      "domain": "global",
      "reason": "insufficientPermissions",
      "message": "Insufficient Permission: Request had insufficient authentication scopes."
    }],
  "code": 403,
  "message": "Insufficient Permission: Request had insufficient authentication scopes."
 }
}
Run Code Online (Sandbox Code Playgroud)

我不确定如何解决此问题。任何方向将不胜感激!

小智 11

我认为Google Drive API端点需要包含在您的范围内。我正在将数据从Mailchimp API写入Google表格。

检查一下:https : //www.youtube.com/watch?v=7I2s81TsCnc >这对我很有帮助。

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