【发布时间】:2019-07-03 06:27:52
【问题描述】:
我想使用 Cloud Vision API 来检测标签。使用以下代码通过我的后端文件发出请求。
import {vision} from 'backend/cloudVision.jsw';
let url = {
requests:[
{
image:{
source:{
imageUri: "https://static.wixstatic.com/media/33aa21_89b30ab70dcb480992ec7b96b316a907~mv2_d_2000_2000_s_2.png"
}
},
features:[
{
type:"LABEL_DETECTION",
maxResults:10
}
]
}
]
};
export function button1_click(event) {
vision(url)
.then( (response) => {
console.log(response);
});
}
在我的后端文件 cloudVision.jsw 我有如下 POST 请求设置
import {fetch} from 'wix-fetch';
export async function vision(url) {
const apiKey = "API_KEY_HERE";
const response = await fetch("https://vision.googleapis.com/v1/images:annotate?key=" + apiKey, {
method: 'post',
headers: {
"Content-Type": "application/json"
},
body: url
});
if (response.status >= 200 && response.status < 300) {
const ret = await response.json();
return ret;
}
let res = await response.json();
return res;
}
但是,我在发出 API 请求时收到 400 错误“收到无效的 JSON 有效负载。意外的令牌。\n[object Object]\n ^”。
我认为可能是编码问题,但不确定。
为此使用 Corvid。
【问题讨论】:
标签: javascript google-cloud-platform google-cloud-vision velo