0

我收到com.ibm.watson.developer_cloud.service.exception.UnauthorizedException: Unauthorized: Access is denied due to invalid credentials错误,而我正在使用正确的凭据。我正在这样做..

进口:

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"
 }
} 

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

4

1 回答 1

2

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

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

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

于 2016-05-20T05:40:51.327 回答