简体   繁体   English

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

[英]Bluemix / Watson Natural Language Processing invalid API Key

Have searched, but can't find similar issues in the past year.已搜索,但找不到过去一年中的类似问题。 I'm trying to follow this tutorial , but things seem to have changed since it was published in April.我正在尝试遵循本教程,但自 4 月发布以来,情况似乎发生了变化。 I've got the PubNub Modules built and have registered a Bluemix Watson account and set up a Natural Language Understanding Service.我已经构建了 PubNub 模块并注册了一个 Bluemix Watson 帐户并设置了一个自然语言理解服务。

It when I try to run the test package in PubNub, I receive the error:当我尝试在 PubNub 中运行测试包时,收到错误消息:

23:24:12 js: 23:24:12 js:

[" TypeError: Cannot read property 'type' of undefined at Sentiment/IBM Watson.js:46:43 at process._tickCallback (internal/process/next_tick.js:109:7)"] Error at Sentiment/IBM Watson.js:76:21 at process._tickCallback (internal/process/next_tick.js:109:7) [“类型错误:无法在情绪/IBM Watson.js:46:43 at process._tickCallback (internal/process/next_tick.js:109:7)”处读取未定义的属性“类型”] 情绪/IBM Watson.js 中的错误:76:21 在 process._tickCallback (internal/process/next_tick.js:109:7)

23:24:13 js: 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\" }

The tutorial code for the api is this: 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';

but it seems as the the API format for Bluemix has changed since the tutorial was written.但似乎自本教程编写以来,Bluemix 的 API 格式发生了变化。 The Bluemix credentials are now in the format: Bluemix 凭证现在采用以下格式:

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

As someone who comes from using R as a statistical calculator and just programmed his first (primitive) battleship game in Python last week, any help much appreciated!作为一个使用 R 作为统计计算器并且上周刚刚用 Python 编写他的第一个(原始)战舰游戏的人,非常感谢任何帮助!

As you can see:如你看到的:

IBM Bluemix just announced the retirement of the AlchemyAPI service . IBM Bluemix 刚刚宣布 停用 AlchemyAPI 服务 They say to use instead the Natural Language Understanding service, also under Watson.他们说改用自然语言理解服务,也在 Watson 下。

Natural language understanding doesn't use API KEY like AlchemyAPI.自然语言理解不像 AlchemyAPI 那样使用 API KEY。 When you create your service inside IBM Bluemix, you can saw in the Service Credentials your username and password :当您在 IBM Bluemix 中创建您的服务时,您可以在服务凭证中看到您的usernamepassword

在此处输入图片说明

So, for use Natural Language Understading with Javascript, you need to follow the API Reference:因此,要在 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));
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM