Search code examples
pythongoogle-app-enginegoogle-apigoogle-oauthgoogle-api-python-client

oauth2client.client.ApplicationDefaultCredentialsError: 'type', 'authorized_user' or 'service_account' values should be set


I'm trying to access the BigQuery API from my Python script. At the moment I'm experimenting only trying to get this sample to run.

I've created credentials, set the environment variable and ran the script, only to get this error:

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)

Well, it isn't set in the JSON file:

{"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"]}}

Since I downloaded the JSON from the Google console, it should just work? I do not know what 'type' I would need to define.


Solution

  • The JSON file that you provided is for an OAuth client. When you using application default credentials, you need to provide a JSON service account key. Try going to this page, clicking "Create service account", filling out the form, and choosing "Furnish a new private key."