使用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,错误:未找到"
答案 0 :(得分:1)
您正尝试使用classify
Sentiment
方法
请参阅https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/%3Csentiment%3E/classify
以下代码对我有用。您只需要替换username
和password
NaturalLanguageClassifier service = new NaturalLanguageClassifier();
service.setUsernameAndPassword("<username>", "<password>");
Classification classification = service.classify("<classifier-id>", "Is it sunny?").execute();
System.out.println(classification);