8
votes

It looks that google-cloud vision Python client (google.cloud.vision.client.Client) doesn't have an option to accept api-key.

https://googlecloudplatform.github.io/google-cloud-python/stable/vision-client.html

How can I use the client with api-key authentication?

1
Try to set GCLOUD_KEYFILE environment variable equal to path to your .json key file. At least this is how it works in Ruby.Nakilon

1 Answers

1
votes

I'm only adding this for future readers because no other answer exists for a while now (I've also added a bounty):

from googleapiclient.discovery import build

# ...

service = build('vision', 'v1', developerKey=API_KEY, cache_discovery=False)
image_b64 = base64.b64encode(image_bytes).decode()
return service.images().annotate(body={
    'requests': [{
        'image': {
            'content': image_b64
        },
        'features': [{
            'type': 'DOCUMENT_TEXT_DETECTION',
            'maxResults': 5,
        }]
    }]
}).execute()

This (python) sample obviously does not use the client in question, but this is how I went at it at the moment to do simple OCR.

You can change the features or the image specification to fit your needs.