【发布时间】:2018-04-10 13:08:49
【问题描述】:
我正在尝试将我的 Java 应用程序连接到 Watson NLU 服务。首先,我尝试按照Bluemix 的教程进行操作。我在 Bluemix 上创建了一个服务并导入了 watson Java SDK。使用本教程代码,我不断收到 401 - 未授权响应。 (当然我更改了服务的用户名和密码)。
我猜是缺少了什么,但我不知道是什么。
NaturalLanguageUnderstanding service = new NaturalLanguageUnderstanding(
NaturalLanguageUnderstanding.VERSION_DATE_2017_02_27,
"{username}",
"{password}"
);
String text = "IBM is an American multinational technology " +
"company headquartered in Armonk, New York, " +
"United States, with operations in over 170 countries.";
EntitiesOptions entitiesOptions = new EntitiesOptions.Builder()
.emotion(true)
.sentiment(true)
.limit(2)
.build();
KeywordsOptions keywordsOptions = new KeywordsOptions.Builder()
.emotion(true)
.sentiment(true)
.limit(2)
.build();
Features features = new Features.Builder()
.entities(entitiesOptions)
.keywords(keywordsOptions)
.build();
AnalyzeOptions parameters = new AnalyzeOptions.Builder()
.text(text)
.features(features)
.build();
AnalysisResults response = service
.analyze(parameters)
.execute();
System.out.println(response);
【问题讨论】: