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. I've got the PubNub Modules built and have registered a Bluemix Watson account and set up a Natural Language Understanding Service.

It when I try to run the test package in PubNub, I receive the error:

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)

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:

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. The Bluemix credentials are now in the format:

{
  "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!

Answers:

Answer

As you can see:

IBM Bluemix just announced the retirement of the AlchemyAPI service. They say to use instead the Natural Language Understanding service, also under Watson.

Natural language understanding doesn't use API KEY like AlchemyAPI. When you create your service inside IBM Bluemix, you can saw in the Service Credentials your username and password:

enter image description here

So, for use Natural Language Understading with Javascript, you need to follow the API Reference:

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

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.