Google Vision API empty response to image stored in Google Cloud Storage

I am trying to use the cloud vision API and I can make a successful request, but my answer is returned empty, even with the test image provided in the API docs.

Request body:

const imagePath = `gs://[bucket_name]/faulkner.jpg`;
const requestObject = {
  requests: [
    {
      image: {
        source: {
          gcsImageUri: imagePath
        }
      },
      features:[
        {
          type: 'LABEL_DETECTION',
          maxResults: 100
        }
      ]
    }
  ]
};

faulkner.jpg

Answer body:

{
  "responses": [{}]
}

I even tried using the cloud API console and copying the request fields, and this also does not work.

const apiKey = 'myAPIKey';
const fields = `fields=responses(labelAnnotations)&`;
const visionAPI = `https://vision.googleapis.com/v1/images:annotate?${fields}key=${apiKey}`;

Any help would be greatly appreciated.

+4
source share
3 answers

I had this exact problem, this is what worked for me ...

  • You do not need OAuth, just an API key.

Here is what I did wrong ...

HTTP- ,

{data: requestBody }

,

// My old call
HTTP.call("POST", "https://vision.googleapis.com/v1/images:annotate?key=myAPIKey", requestBody, myCallback);

// To my new call
HTTP.call("POST", "https://vision.googleapis.com/v1/images:annotate?key=myAPIKey", {data: requestBody}, myCallback);

// reqeustBody example

{
  "requests":
    [
      {
        "features":
          [
            {
              "type": "LABEL_DETECTION"
            } 
          ],
        "image":
          {
            "source":
              {
                "gcsImageUri": "gs://myBucketNameHere/myDemoImageNameHere.jpg"
              }
          }
      }
    ]
  }

: , .

  • Google Cloud Platform.
  • , .
  • -, , FACE_DETECTION .
  • Google Cloud .

demo-image.jpg, , requestBody.

0

OAuth2 . Vision API gCS Images API-.

0

oauth2? , gcloud:

  • json key
  • gcloud :

    gcloud auth activate-service-account --key-file <service-account-file.json>
    
  • gcloud auth print-access-token curl :

    curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "content-type: application/json" \
        --data-binary '{"requests": [{"image": {"source": {"gcs_image_uri": "gs://your-bucket/your-object.jpg"}}, "features":  [{"type": "LABEL_DETECTION", "maxResults": 100}]}]}' \
        "https://vision.googleapis.com/v1/images:annotate?alt=json"
    
, oauth2, , , .
0

All Articles