2017-10-28 124 views
1

已搜索,但无法在过去一年中找到类似问题。我试图遵循this tutorial,但自从4月份发布以来似乎有所改变。我已经构建了PubNub模块,并已注册Bluemix Watson帐户并设置了自然语言理解服务。Bluemix/Watson自然语言处理无效API密钥

它,当我尝试运行PubNub测试包,我收到错误:

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记者:

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

正如你可以看到:

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

自然语言理解不使用像AlchemyAPI API密钥。

enter image description here

因此,对于使用自然语言Understading使用Javascript,您需要按照API参考:

当您创建IBM Bluemix内为您服务,您可以在服务凭据您 usernamepassword看到
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)); 
});