1

向cloudsight api发送请求时出现以下错误

{"error":{"image":["至少必须设置 image 或 remote_image_url 之一"]}}

你能告诉我缺少什么吗?

代码片段:

var xhr = new XMLHttpRequest();
var url = "http://api.cloudsightapi.com/image_requests";

xhr.open("POST", url, true);
xhr.setRequestHeader('Content-type', 'application/json');
xhr.setRequestHeader('authorization', 'CloudSight <MY_API_KEY>');
xhr.setRequestHeader('cache-control', 'no-cache');

xhr.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        var myArr = JSON.parse(this.responseText);
        alert(http.responseText);
    }
};

xhr.send(JSON.stringify({"remote_image_url":"http://englishbookgeorgia.com/blogebg/wp-content/uploads/2015/08/husky.jpg" ,"locale":"en_US"}));
4

1 回答 1

2

您需要使用此处记录的 v1 api:https ://cloudsight.docs.apiary.io/#reference/0/images-collection

这是使用 v1 API 的更正块。

var xhr = new XMLHttpRequest();
var url = "http://api.cloudsightapi.com/v1/images";

xhr.open("POST", url, true);
xhr.setRequestHeader('Content-type', 'application/json');
xhr.setRequestHeader('authorization', 'CloudSight <Your API Key>');
xhr.setRequestHeader('cache-control', 'no-cache');

xhr.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        var myArr = JSON.parse(this.responseText);
        alert(this.responseText);
    }
};

xhr.send(JSON.stringify({"remote_image_url":"http://englishbookgeorgia.com/blogebg/wp-content/uploads/2015/08/husky.jpg" ,"locale":"en_US"}));

您使用的 v0 api 需要 JSON 中的根图像对象,因此:

{
  image: {
    remote_image_url: "example",
    locale: "en_US"
  }
}

这是错误的原因。

于 2018-05-22T10:32:32.990 回答