I am trying to use the cloud vision API and I am able to make a successful request, but my response comes back empty, even with the test image provided on 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
}
]
}
]
};
Response Body:
{
"responses": [{}]
}
I have even tried using the cloud API console and copy the request fields, and that too 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.
I was having this exact issue, this is what worked for me...
This is what I was doing wrong...
In my HTTP call I needed to wrap my request in a new object literal as in
{data: requestBody }
To clarify,
// 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"
}
}
}
]
}
NOTE: A few things that need to be done.
I am using the very same call above with my image named demo-image.jpg and everything works now that I wrapped the requestBody.