当前位置: 动力学知识库 > 问答 > 编程问答 >

android - 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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: