Я пытаюсь отправить данные в API Google Vision. Butt я всегда получаю код ответа 400 - плохой запрос. У меня уже нет идей.API Google Vision
Я прочитал и пытался использовать эти ссылки:
https://cloud.google.com/vision/docs/requests-and-responses https://cloud.google.com/vision/docs/detecting-text https://developers.google.com/apis-explorer/?hl=ru#p/vision/v1/vision.images.annotate
И я подошел к этому:
Вот мои данные на сообщение:
var dataToSend = {
"requests": [
{
"image": {
"content": imageData
},
"features": [
{
"type": "TYPE_UNSPECIFIED",
"maxResults": 50
},
{
"type": "LANDMARK_DETECTION",
"maxResults": 50
},
{
"type": "FACE_DETECTION",
"maxResults": 50
},
{
"type": "LOGO_DETECTION",
"maxResults": 50
},
{
"type": "LABEL_DETECTION",
"maxResults": 50
},
{
"type": "TEXT_DETECTION",
"maxResults": 50
},
{
"type": "SAFE_SEARCH_DETECTION",
"maxResults": 50
},
{
"type": "IMAGE_PROPERTIES",
"maxResults": 50
}
]
}
]
};
И вот мое сообщение:
$.ajax({
url: "https://vision.googleapis.com/v1/images:annotate?fields=responses&key={MY CREATED KEY}",
type: "POST",
data: dataToSend,
success: function (reponse) {
console.log(reponse);
},
});
Вот данные из консоли (СОДЕРЖАНИЕ IS BLANK НАПРИМЕР (не размещать Воле base64)):
И вот ответ:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"requests[0][features][0][type]\": Cannot bind query parameter. Field 'requests[0][features][0][type]' could not be found in request message.\nInvalid JSON payload received. Unknown name \"requests[0][features][0][maxResults]\": Cannot bind query parameter. Field 'requests[0][features][0][maxResults]' could not be found in request message.\nInvalid JSON payload received. Unknown name \"requests[0][image][content]\": Cannot bind query parameter. Field 'requests[0][image][content]' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"requests[0][features][0][type]\": Cannot bind query parameter. Field 'requests[0][features][0][type]' could not be found in request message."
},
{
"description": "Invalid JSON payload received. Unknown name \"requests[0][features][0][maxResults]\": Cannot bind query parameter. Field 'requests[0][features][0][maxResults]' could not be found in request message."
},
{
"description": "Invalid JSON payload received. Unknown name \"requests[0][image][content]\": Cannot bind query parameter. Field 'requests[0][image][content]' could not be found in request message."
}
]
}
]
}
}
Где моя ошибка?
Вы преобразовали изображение в формат базы 64 –