2017-10-28 177 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)); 
});