IBM Watson Visual Recognition:UnauthorizedException

时间:2016-05-19 20:06:03

标签: android ibm-cloud ibm-watson visual-recognition

我正在使用正确的凭据, com.ibm.watson.developer_cloud.service.exception.UnauthorizedException:Unauthorized:由于凭据无效而拒绝访问错误。我这样做..

进口:

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上,视觉识别凭据就像这样

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

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

1 个答案:

答案 0 :(得分:2)

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

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

(密码,用户名)。我只是尝试使用正确的订单,它对我来说很好。