Gspread 从 Python 传递凭证而不是 JSON

Alv*_*rid 5 python gspread google-sheets-api

我使用 Gspread 尝试将 JSON 文件(Google API 服务应用程序凭据)上的内容作为脚本上的 python 字典传递。无论我在哪里使用脚本,我都尽量不携带 json 文件。

当我尝试在以下行中传递字典而不是 json 文件时,出现以下错误:

credentials = ServiceAccountCredentials.from_json_keyfile_name(auth_gdrive(), scope)
Run Code Online (Sandbox Code Playgroud)

类型错误:预期的 str、bytes 或 os.PathLike 对象,未设置

### auth_gdrive() returns a dictionary like this:

def auth_gdrive():
    dic = {
        "type": "miauuuuuu",
        "pass": "miauuuu"
    }
Run Code Online (Sandbox Code Playgroud)

我不允许展示 dic 中的真实内容。

Alv*_*rid 10

由于我想从应用程序内部传递凭据详细信息,而不是从我无法使用的 json 文件传递​​:

ServiceAccountCredentials.from_json_keyfile_name()

from_json_keyfile_name() 需要一个 json 文件。但查看文档我发现以下内容:

ServiceAccountCredentials.from_json_keyfile_dict()

这将需要一个 dict 对象,这就是我所需要的。

关联:

https://oauth2client.readthedocs.io/en/latest/source/oauth2client.service_account.html

再次感谢大家