Bluemix / Watson自然语言处理无效的API密钥
曾经search过,但在过去一年里找不到类似的问题。 我试图按照这个教程 ,但自从四月份发布以来似乎已经发生了变化。 我已经构build了PubNub模块并注册了一个Bluemix Watson帐户,并设置了一个自然语言理解服务。
当我尝试在PubNub中运行testing包时,我收到错误消息:
23:24:12 js:
[“TypeError:无法读取在Sentiment / IBM Watson.js:46:43在process._tickCallback(内部/进程/ next_tick.js:109:7)未定义的属性'types”] 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\" }
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中编写了他的第一个(原始)战舰游戏,任何帮助都非常感谢!
如你看到的:
IBM Bluemix刚刚宣布AlchemyAPI服务的退役 。 他们说,也可以在Watson下使用自然语言理解服务。
自然语言理解不像AlchemyAPI那样使用API KEY。 在IBM Bluemix中创build服务时,可以在Service Credentials中看到您的username
和password
:
所以,对于使用JavaScript的自然语言parsing,您需要遵循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)); });
- 使用Node.js查看官方API参考
- 演示给你看了NLU API的工作原理。
- 从AlchemyAPI迁移。