【问题标题】:oauth2client.client.ApplicationDefaultCredentialsError: 'type', 'authorized_user' or 'service_account' values should be setoauth2client.client.ApplicationDefaultCredentialsError:应设置“类型”、“授权用户”或“服务帐户”值
【发布时间】:2016-02-10 18:58:17
【问题描述】:

我正在尝试从我的 Python 脚本访问 BigQuery API。目前我只是在尝试让this sample 运行。

我创建了凭据,设置了环境变量并运行了脚本,却得到了这个错误:

oauth2client.client.ApplicationDefaultCredentialsError: An error was encountered while reading json file: /PATH/TO/MY/google_api_credentials.json (pointed to by GOOGLE_APPLICATION_CREDENTIALS environment variable): 'type' field should be defined (and have one of the 'authorized_user' or 'service_account' values)

嗯,它没有在 JSON 文件中设置:

{"installed":{"client_id":"blahblah.apps.googleusercontent.com","project_id":"blahblah","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"blahblah","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}

既然我从 Google 控制台下载了 JSON,它应该可以工作吗?我不知道我需要定义什么“类型”。

【问题讨论】:

    标签: python google-app-engine google-api google-oauth google-api-python-client


    【解决方案1】:

    您提供的 JSON 文件用于 OAuth 客户端。当您使用应用程序默认凭据时,您需要提供 JSON 服务帐户密钥。尝试转到this page,点击“创建服务帐户”,填写表格,然后选择“提供新的私钥”。

    【讨论】:

    • 谢谢。不得不说,谷歌关于这些东西的文档有时候有点垃圾!
    猜你喜欢
    • 2013-08-21
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    • 2019-03-15
    • 2016-05-19
    • 1970-01-01
    • 2020-02-22
    • 2020-01-06
    相关资源
    最近更新 更多