简体   繁体   中英

IBM Watson Visual Recognition : UnauthorizedException

I am getting com.ibm.watson.developer_cloud.service.exception.UnauthorizedException: Unauthorized: Access is denied due to invalid credentials error while i am using the right credentials. I am doing like this..

Imports :

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

Code :

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();

Dependencies :

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

Where on Bluemix the Visual Recognition credentials are like this

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

Please help me to solve the issue. Thanks in advance!

This may be an error in your question, rather than an error in your code, however please double check that you pass to setUsernameAndPassword method the parameters in the correct order (username, password) as specified in the API Reference . Looking at your code I see

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

that is (password, username) . I've just tried using the correct order and it works fine for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM