Om3*_*3ga 7 javascript node.js
我正在为nodejs 使用Microsoft Cognitive Services api.我有以下代码
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);
});
Run Code Online (Sandbox Code Playgroud)
但是,当我执行此代码时,我得到以下错误
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
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
看起来cognitive-services模块的文档不正确:您需要在cognitiveServices.face(...)没有的情况下打电话new.
如果你看一下https://github.com/joshbalfour/node-cognitive-services/blob/master/api/face.js,你可以看到它face被定义为一个箭头函数,这使它不是一个构造函数.有关具体情况的详细信息,请参阅/sf/answers/2592632031/.
编辑:看起来问题已在此处报告:https://github.com/joshbalfour/node-cognitive-services/issues/2