我正在使用
Microsoft Cognitive Services api for nodejs.我有以下代码
@H_404_2@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);
});
@H_404_2@const face = new cognitiveServices.face({
^
TypeError: cognitiveServices.face is not a constructor
at Object.<anonymous> (/Users/..../face.js:3:14)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
解决方法
看起来认知服务模块的文档是不正确的:您需要在没有new的情况下调用cognitiveServices.face(…).
如果查看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