IBM沃森。自然语言。获取:401凭据无效,但它们是正确的。来自java sdk

时间:2017-11-02 12:45:16

标签: java sdk ibm-cloud

使用java sdk。运行示例:com.ibm.watson.developer_cloud.natural_language_classifier.v1;

替换了从IBM站点粘贴的userName get:SEVERE:POST https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/%3Csentiment%3E/classify,状态:401,错误:未授权

core.src.main.java.com.ibm.watson.developer_cloud.service.exception.UnauthorizedException:未经授权:由于凭据无效,访问被拒绝。提示:您是否设置了端点?

IBM网站引用:" url":" https://gateway.watsonplatform.net/natural-language-understanding/api", 示例代码包含:... / natural-language-classifier

试过两个。使用/..understand返回" 404,错误:未找到"

1 个答案:

答案 0 :(得分:1)

您正尝试使用classify

调用Sentiment方法

请参阅https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/%3Csentiment%3E/classify

以下代码对我有用。您只需要替换usernamepassword

NaturalLanguageClassifier service = new NaturalLanguageClassifier();
service.setUsernameAndPassword("<username>", "<password>");

Classification classification = service.classify("<classifier-id>", "Is it sunny?").execute();
System.out.println(classification);