Livewire tom
Livewire tom

Reputation: 1

IBM Watson. natural-language. Get :401 Invalid credentials, but they are correct. from java sdk

Using java sdk. Running examples: com.ibm.watson.developer_cloud.natural_language_classifier.v1;

Replaced userName, pw pasted from IBM site get:SEVERE: POST https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/%3Csentiment%3E/classify, status: 401, error: Not Authorized

core.src.main.java.com.ibm.watson.developer_cloud.service.exception.UnauthorizedException: Unauthorized: Access is denied due to invalid credentials. Tip: Did you set the Endpoint?

IBM site references:"url": "https://gateway.watsonplatform.net/natural-language-understanding/api", Example code has: .../natural-language-classifier

Tried both. Using /..understanding returns "404, error: not found"

Upvotes: 0

Views: 446

Answers (1)

German Attanasio
German Attanasio

Reputation: 23653

You are trying to call the classify method with Sentiment

See https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/%3Csentiment%3E/classify

The code below is working for me. You just need to replace username and password

NaturalLanguageClassifier service = new NaturalLanguageClassifier();
service.setUsernameAndPassword("<username>", "<password>");

Classification classification = service.classify("<classifier-id>", "Is it sunny?").execute();
System.out.println(classification);

Upvotes: 1

Related Questions