oauth2client.client.ApplicationDefaultCredentialsError:' type',' authorized_user'或者' service_account'应设置值

时间:2016-02-10 18:58:17

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

我试图从我的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,它应该可以正常工作吗?我不知道'键入'我需要定义。

1 个答案:

答案 0 :(得分:2)

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