我对nodejs使用Microsoft Cognitive Services api。我有以下代码
final long count = Stream.of("Cristian","Daniel","Ortiz","Cuellar")
.filter(new Predicate<String>() {
public boolean test(String s) {
return matcher(s).find();
}
})
.count();
然而,当我执行此代码时,我得到以下错误
const cognitiveServices = require('cognitive-services');
const face = new cognitiveServices.face({
API_KEY: yourApiKey
})
const parameters = {
returnFaceId: "true"
returnFaceLandmarks: "false"
};
const body = {
"url": "URL of input image"
};
face.detect({
parameters,
body
})
.then((response) => {
console.log('Got response', response);
})
.catch((err) => {
console.error('Encountered error making request:', err);
});
如何解决此错误?
答案 0 :(得分:5)
cognitive-services
模块的文档似乎不正确:您需要在没有cognitiveServices.face(...)
的情况下致电new
。
如果查看https://github.com/joshbalfour/node-cognitive-services/blob/master/api/face.js,可以看到face
被定义为箭头函数,这使它不是构造函数。有关案例原因的详细信息,请参阅https://stackoverflow.com/a/37037600/483595。
修改:看起来此处已报告此问题:https://github.com/joshbalfour/node-cognitive-services/issues/2