【发布时间】:2019-06-29 11:30:08
【问题描述】:
是否可以从 dict 而不是文件加载凭据?这将使在云函数中使用短脚本变得更容易,因为这样就不需要上传文件了。通常授权是这样的:
import pygsheets
gc = pygsheets.authorize(service_file='client_secret.json')
如果凭据存储在 a 变量中,如下所示:
secret = {
"type": "service_account",
"project_id": "XXXXXXXXXX",
"private_key_id": "XXXXXXXXXX",
"private_key": "XXXXXXXXXX"
"client_email": "XXXXXXXXXX",
"client_id": "XXXXXXXXXX",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "XXXXXXXXXX"
}
是否可以使用custom_credentials 而不是service_file 加载它们? docs 没有给出任何关于如何使用它的说明,除了“这个选项将忽略任何其他参数”。以下代码:
import pygsheets
gc = pygsheets.authorize(custom_credentials=secret)
抛出以下错误:
AttributeError: 'dict' object has no attribute 'before_request'
还有其他方法可以做到这一点吗?例如,gspread 中有以下选项:
ServiceAccountCredentials.from_json_keyfile_dict(keyfile_dict, scope)
有什么建议吗?谢谢!!!
【问题讨论】:
标签: python python-3.x gspread pygsheets