使用此代码:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://www.googleapis.com/auth/spreadsheets',
'https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('Consumer
Outr.json', scope)
gc = gspread.authorize(credentials)
nonStartFreeTrial = gc.open("Consumer Outreach")[0]
我需要使用Google提供的服务凭证API,而不是常规的API密钥,而且我不断得到:
APIError: {
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}
我正在ipynb中编写此代码,理想情况下将能够从活动单元格访问电子表格。我读过可以使用API密钥解决此问题,但是gspread文档建议“服务帐户凭据”是最好的方法。真的不知道要解决什么(对Google API来说是新的!)。