Reputation: 797
I have signed up for free trial in google cloud platform.I created a project and OAuth 2.0 client IDs.I got a json file also.I installed required packages using
pip install --upgrade google-api-python-client
pip install google-cloud
Now i need to access text extraction from image API from google in my python program.My code is(here)
from google.cloud import vision
client = vision.Client()
with open('./image.jpg', 'rb') as image_file:
image = client.image(content=image_file.read())
texts = image.detect_text()
print texts[0].description
I have JSON file,client id,Client secret.How to integrate these credintials in above code to access google api?
Upvotes: 0
Views: 2072
Reputation: 1793
Assuming you want to access the cloud vision API locally since on App Engine it should "just work".
To authenticate using a service account JSON keyfile you need to point to it using an environment variable:
$ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"
You can also authenticate using the Google Cloud SDK if it's available
$ gcloud beta auth application-default login
https://googlecloudplatform.github.io/google-cloud-python/stable/google-cloud-auth.html#overview
Upvotes: 1