0
votes

I am trying to run the Face Detection Example in Google's Cloud Vision API. I am trying to run [faces.py here][1].

When I run the following:

faces.py demo-picture.jpg

below is the error I get:

ubuntu@ubuntu-VirtualBox:~/Documents/code/python-    stuff/googleapis/cloudvisionapi/cloud-vision/python/face_detection$ python     faces.py demo-image.jpg 
Traceback (most recent call last):
  File "faces.py", line 121, in <module>
    main(args.input_image, args.output, args.max_results)
  File "faces.py", line 98, in main
    faces = detect_face(image, max_results)
  File "faces.py", line 62, in detect_face
    service = get_vision_service()
  File "faces.py", line 35, in get_vision_service
    credentials = GoogleCredentials.get_application_default()
  File "/home/ubuntu/.local/lib/python2.7/site-     packages/oauth2client/client.py", line 1398, in get_application_default
    return GoogleCredentials._get_implicit_credentials()
  File "/home/ubuntu/.local/lib/python2.7/site-    packages/oauth2client/client.py", line 1388, 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 https://developers.google.com/accounts/docs/application-    default-credentials for more information.
ubuntu@ubuntu-VirtualBox:~/Documents/code/python-    stuff/googleapis/cloudvisionapi/cloud-vision/python/face_detection$ 
  [1]: https://github.com/GoogleCloudPlatform/cloud-    vision/tree/master/python/face_detection

I guess my question is -- how do I do this:

Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials.

1

1 Answers

0
votes

You need to download the service-account key; typically a JSON file. If you have not created the credentials/obtained the key, follow the steps:

Go to your API manager;
Create credentials;
Choose "Service Account Key";
Select "Key Type" as JSON.

After this point, you should obtain a JSON file.

Once you obtain the key, go to your BASHRC (~/.bashrc) and add the following:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/JSON

Then restart your bash by exec bash

Now, re-run your faces.py.