Bluemix / Watson Natural Language Processing无效的API密钥

时间:2017-10-28 22:30:00

标签: javascript node.js ibm-cloud ibm-watson pubnub

已搜索过,但在过去一年中找不到类似的问题。我试图关注this tutorial,但自4月发布以来,情况似乎发生了变化。我已经构建了PubNub模块并注册了Bluemix Watson帐户并设置了自然语言理解服务。

当我尝试在PubNub中运行测试包时,收到错误:

23:24:12 js:

  

[“TypeError:无法读取未定义的属性'type'   Sentiment / IBM Watson.js:46:43 at process._tickCallback   (internal / process / next_tick.js:109:7)“] Sentiment / IBM出错   Watson.js:76:21 at process._tickCallback   (内部/过程/ next_tick.js:109:7)

23:24:13 js:

{ "body": "{ \"status\": \"ERROR\", \"statusInfo\": \"invalid-api-key\", \"usage\": \"By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html\", \"totalTransactions\": \"1\", \"language\": \"unknown\" }

api的教程代码是:

export default (request) => {
    // url for sentiment analysis api
    const apiUrl = 'https://gateway-a.watsonplatform.net/calls/text/TextGetTextSentiment';

    // api key
const apiKey = 'Your_API_Key';

但似乎自编写教程以来,Bluemix的API格式已发生变化。 Bluemix凭据现在采用以下格式:

{
  "url": "https://gateway.watsonplatform.net/natural-language-understanding/api",
  "username": "x",
  "password": "y"
}

作为一名使用R作为统计计算器并且上周刚用Python编写了他的第一个(原始)战舰游戏的人,任何帮助都非常赞赏!

1 个答案:

答案 0 :(得分:1)

如你所见:

  

IBM Bluemix刚刚宣布了retirement of the AlchemyAPI service。   他们说使用自然语言理解服务,   沃森也在。

自然语言理解不使用像AlchemyAPI这样的API KEY。在IBM Bluemix中创建服务时,您可以在服务凭证中看到usernamepassword

enter image description here

因此,要使用自然语言Understading with Javascript,您需要遵循API参考:

var NaturalLanguageUnderstandingV1 = require('watson-developer-cloud/natural-language-understanding/v1.js');
var natural_language_understanding = new NaturalLanguageUnderstandingV1({
  'username': '{username}', //Service Credentials
  'password': '{password}', //Service Credentials
  'version_date': '2017-02-27'
});

var parameters = {
  'text': 'IBM is an American multinational technology company headquartered in Armonk, New York, United States, with operations in over 170 countries.',
  'features': {
    'entities': {
      'emotion': true,
      'sentiment': true,
      'limit': 2
    },
    'keywords': {
      'emotion': true,
      'sentiment': true,
      'limit': 2
    }
  }
}

natural_language_understanding.analyze(parameters, function(err, response) {
  if (err)
    console.log('error:', err);
  else
    console.log(JSON.stringify(response, null, 2));
});