TypeError:cognitiveServices.face不是构造函数

时间:2016-09-22 13:48:43

标签: javascript node.js

我对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);
      });

如何解决此错误?

1 个答案:

答案 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