Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vision-client doesn't supprt api-key

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?

like image 825
etusji Avatar asked Nov 18 '16 23:11

etusji


1 Answers

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.

like image 116
Reut Sharabani Avatar answered Oct 07 '22 00:10

Reut Sharabani