【发布时间】:2016-03-09 07:47:27
【问题描述】:
我正在尝试使用 Alloy Appcelerator 的 Google vision API v1
我创建一个请求 HTTPClient 并调用 API https://vision.googleapis.com/v1/images:annotate?key=MY_APP_KEY
但我从谷歌得到了回复文本:
{
error = {
code = 400;
details = (
{
"@type" = "type.googleapis.com/google.rpc.BadRequest";
fieldViolations = ({
description = "Invalid JSON payload received. Unknown name \"request\": Cannot bind query parameter. Field 'request' could not be found in request message.";
});
}
);
message = "Invalid JSON payload received. Unknown name \"request\": Cannot bind query parameter. Field 'request' could not be found in request message.";
status = "INVALID_ARGUMENT";
};
}
还有我的代码使用 Alloy 的 HTTP 请求
var requests =
{
"requests":[
{
"image":{
"content": "image_have_encodebase64",
},
"features":[
{
"type":"TEXT_DETECTION",
"maxResults":1
}
]
}
]
};
var xhr = Titanium.Network.createHTTPClient();
xhr.open("POST", 'https://vision.googleapis.com/v1/images:annotate?key=MY_APP_KEY');
xhr.send(JSON.stringify(requests));
感谢您的帮助
【问题讨论】:
-
查看API,我注意到数组名称应该是requests(复数)而不是request。让我知道它是否有帮助
-
感谢您的帮助,但如果我将请求更改为请求,则会出现同样的错误
-
你试过 JSON.stringify() 了吗?喜欢:
xhr.send(JSON.stringify(requests)); -
嗨 Carlos Henrique Lustosa,我尝试这种方式但没有成功
-
亲爱的,我已经修好了。因为我encode64的字符串长度太长了,所以发不出去。我必须为标题设置内容长度。感谢@Fokke-Appcelerator - Appcelerator,Carlos Henrique Lustosa 的支持
标签: google-api appcelerator appcelerator-titanium google-vision