alicankargin alicankargin - 2 years ago 221
Python Question

google-api-python-client doesn't work with developer key

I can't get this script working. I replace the DEVELOPER_KEY with the API key I have created from Google APIs. I would really appreciate if someone can help me out. The script is from this page:


from apiclient.discovery import build
from apiclient.errors import HttpError
from import argparser

# Set DEVELOPER_KEY to the API key value from the APIs & auth > Registered apps
# tab of
# Please ensure that you have enabled the YouTube Data API for your project.


I get the following error message.

Traceback (most recent call last):
File "", line 16, in <module>
File "/home/alican/.local/lib/python2.7/site-packages/oauth2client/", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/alican/.local/lib/python2.7/site-packages/googleapiclient/", line 226, in build
File "/home/alican/.local/lib/python2.7/site-packages/oauth2client/", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/alican/.local/lib/python2.7/site-packages/googleapiclient/", line 358, in build_from_document
credentials = _auth.default_credentials()
File "/home/alican/.local/lib/python2.7/site-packages/googleapiclient/", line 40, in default_credentials
return oauth2client.client.GoogleCredentials.get_application_default()
File "/home/alican/.local/lib/python2.7/site-packages/oauth2client/", line 1264, in get_application_default
return GoogleCredentials._get_implicit_credentials()
File "/home/alican/.local/lib/python2.7/site-packages/oauth2client/", line 1254, in _get_implicit_credentials
raise ApplicationDefaultCredentialsError(ADC_HELP_MSG)
oauth2client.client.ApplicationDefaultCredentialsError: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See for more information.

Answer Source

If you want to use google-api-python-client version 1.6 do the following. Go to Select create credentials, choose service account key, choose App Engine default service account, download the JSON file and put it in your project folder. Then set the it as the environment variable GOOGLE_APPLICATION_CREDENTIALS.

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./google_application_credentials.json"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download