我正在为nodejs使用Microsoft Cognitive Services api。我有以下代码TypeError:cognitiveServices.face不是构造函数
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);
});
然而,当我执行这个代码,我得到以下错误
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
我怎样才能解决这个问题?
你有那个模块的顶部需要声明,对不对?你可以编辑你的问题,包括该声明?同样,根据https://github.com/joshbalfour/node-cognitive-services#installation上的“安装和入门”步骤验证您是否正确安装了认知服务api会很好。 – ArthurDenture
是的,我有,我更新了我的问题。 – 2619
嗨,我的答案是否适合你?我看到赏金仍然开放... – ArthurDenture