2017-04-10 81 views
0

这里是我的代码使用Microsoft脸API的对象返回400图片无效或参数无效

<script type="text/javascript"> 
$(function() { 
    var params = { 
     // Request parameters 
     "returnFaceId": "true", 
     "returnFaceLandmarks": "false", 
     "returnFaceAttributes": "{string}", 
    }; 

    $.ajax({ 
     url: "https://westus.api.cognitive.microsoft.com/face/v1.0/detect?" + $.param(params), 
     beforeSend: function(xhrObj){ 
      // Request headers 
      xhrObj.setRequestHeader("Content-Type","application/json"); 
      xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","8b99a9ed839a40a08aa8b529ef0f9b8c"); 
     }, 
     type: "POST", 
     // Request body 
     data: '{ "url": "http://heightline.com/wp-content/uploads/Tom-Cruise-smile.jpg" }' 
    }) 
    .done(function(data) { 
     alert("success"); 
    }) 
    .fail(function() { 
     alert("error"); 
    }); 
}); 

这里是那里有文档的图像从server`enter时约400性反应我进入或访问页面然后它会显示错误的帮助如何解决这个 Here is the image of theres documentation about 400 responce from the server

回答

2

“returnFaceAttributes”:“{}字符串”正在错误。 实际上它是{string}的值。应该指定,即年龄,性别......

尝试用“returnFaceAttributes”:“age”替换“returnFaceAttributes”:“{string}”,它应该可以工作。

检查文档:https://www.microsoft.com/cognitive-services/en-us/face-api/documentation/glossary

+0

不过400错误的性反应 –

+0

请张贴代码,我用你确切的代码与我的变化和它的作品..没有在结尾忘记逗号? – bukajcihaj

+0

在上面的代码我改变字符串与年龄 –