我必须制作一个cordova应用程序,在该应用程序中,用户拍摄照片并使用cloud vision和rest api检查所拍摄的图像。但是,没有Json响应也没有错误返回。
JavaScript- REST API调用-传递从相机插件返回的base64数据
function callREST() {
var _apiKey = "MYKEY"
var _data = {
requests: [
{
image: {
content: imageData //base64 image string
},
features: [
{
type: "IMAGE_PROPERTIES"
}
]
}
]
};
通过以下概述的方法处理REST调用
$.ajax({
type: "GET", //GET, POST, PUT or DELETE
url: "https://vision.googleapis.com/v1/images:annotate" + _apiKey, //INSERT URL!!
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(_data),
success: restSuccess,
error: restError
});
}
如果成功
function restSuccess(result) {
console.log(result);
console.log(responseJSON);
getAllHighValues();
var DominantColor = results;
var data={referenceKey: DominantColor, color:HELPERRESULT.color,score: HELPERRESULT.score};
saveData(data);
}