【问题标题】:Bluemix / Watson Natural Language Processing invalid API KeyBluemix / Watson 自然语言处理 API 密钥无效
【发布时间】:2018-04-10 05:52:30
【问题描述】:

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

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

23:24:12 js:

[" TypeError: 无法读取未定义的属性 'type' at 情绪/IBM Watson.js:46:43 at process._tickCallback (internal/process/next_tick.js:109:7)"] 情绪/IBM 错误 Watson.js:76:21 在 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 编写了他的第一个(原始)战舰游戏,非常感谢任何帮助!

【问题讨论】:

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


    【解决方案1】:

    如你所见:

    IBM Bluemix 刚刚宣布了retirement of the AlchemyAPI service。 他们说改用自然语言理解服务, 也在 Watson 旗下。

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

    因此,要在 Javascript 中使用 Natural Language Understading,您需要遵循 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));
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 2015-07-23
      • 2015-10-10
      相关资源
      最近更新 更多