IBM Watson 视觉识别:UnauthorizedException

IBM Watson Visual Recognition : UnauthorizedException

我在使用正确的凭据时收到 com.ibm.watson.developer_cloud.service.exception.UnauthorizedException:未经授权:由于凭据无效,访问被拒绝 错误。我是这样做的..

进口:

import com.ibm.watson.developer_cloud.visual_recognition.v2_beta.VisualRecognition;
import com.ibm.watson.developer_cloud.visual_recognition.v2_beta.model.VisualClassification;

代码:

service = new VisualRecognition(VisualRecognition.VERSION_DATE_2015_12_02);
service.setUsernameAndPassword("GXXXXxxxxxxx", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); 

File image = new File("src/test/resources/visual_recognition/car.png");
VisualClassification result = service.classify(image).execute();

依赖关系:

compile 'com.ibm.watson.developer_cloud:java-sdk:3.0.0-RC1'

Bluemix 上的 Visual Recognition 凭据是这样的

{
 "credentials": {
 "url": "https://gateway.watsonplatform.net/visual-recognition-beta/api",
 "password": "GXXXXxxxxxxx",
 "username": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
 }
} 

请帮我解决问题。提前致谢!

这可能是您问题中的错误,而不是代码中的错误,但是请仔细检查您是否以正确的顺序传递给 setUsernameAndPassword 方法的参数(用户名, 密码)在 API Reference 中指定。查看您的代码,我明白了

service.setUsernameAndPassword("GXXXXxxxxxxx", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); 

(密码,用户名)。我刚刚尝试使用正确的顺序,对我来说效果很好。