我正在使用 GSpread 尝试将我的 JSON 文件(Google API 服务应用程序凭据)中的内容作为脚本中的 python 字典传递。我尽量不在我携带脚本的任何地方携带 json 文件。
当我尝试在以下行中传递字典而不是 json 文件时出现以下错误:
credentials = ServiceAccountCredentials.from_json_keyfile_name(auth_gdrive(), scope)
TypeError: 预期的 str、bytes 或 os.PathLike 对象,未设置
### auth_gdrive() returns a dictionary like this:
def auth_gdrive():
dic = {
"type": "miauuuuuu",
"pass": "miauuuu"
}
我不允许显示 dic 中的真实内容。
请您参考如下方法:
因为我想从我的应用程序中传递凭证详细信息,而不是从我无法使用的 json 文件中传递:
ServiceAccountCredentials.from_json_keyfile_name()
from_json_keyfile_name() 需要一个 json 文件。但是查看文档我发现了以下内容:
ServiceAccountCredentials.from_json_keyfile_dict()
这需要一个字典对象,这就是我所需要的。
链接:
https://oauth2client.readthedocs.io/en/latest/source/oauth2client.service_account.html
再次感谢大家
