Я хочу получить список корпораций.
curl -X GET --header "Authorization: Bearer xxxxxxxx(about 1200 characters IAM token)" "https://https://gateway-syd.watsonplatform.net/speech-to-text/api/v1/customizations/zzzzz(customization_id)/corpora"
результат (Эта команда завитка выполнена успешно.)
{"corpora": [
{
"out_of_vocabulary_words": 0,
"total_words": 10,
"name": "corpusname",
"status": "analyzed"
},
...
но ... в Java,
HttpURLConnection urlConn = null;
try {
String urlStr ="https://https://gateway-syd.watsonplatform.net/speech-to-text/api/v1/customizations/zzzzz(customization_id)/corpora";
URL url = new URL(urlStr);
urlConn = (HttpURLConnection) url.openConnection();
String token = xxxxxxxx; // about 1200 characters IAM token
urlConn.setRequestProperty("Authorization", "Bearer " + token);
urlConn.setRequestMethod("GET");
urlConn.connect();
int status = urlConn.getResponseCode();
String resMessage = urlConn.getResponseMessage();
System.out.println("## HTTPStatus:" + status + " - " + resMessage); // "## HTTPStatus:400 - Bad Request"
} catch (xxx) {
// ...
}
результат (ошибка)
## HTTPStatus:400 - Bad Request
Я использовал тот же токен IAM ... Почему возникает эта ошибка?
(извините, что Я не очень хорош в Engli sh.)
============= добавлено 2020/03/03
Я использовал watson SDK (ver.6.9 0,2). Но возникает другая ошибка (403) ...
IamOptions options = new IamOptions.Builder()
.accessToken(token)
.url(urlStr) // String urlStr = https://gateway-syd.watsonplatform.net/speech-to-text/api/v1/customizations/zzzzz(customization_id)/corpora
.build();
SpeechToText speechToText = new SpeechToText(options);
System.out.println();
ListCorporaOptions listCorporaOptions = new ListCorporaOptions.Builder()
.customizationId(customizations_id) // String curstomization_id = zzzzz
.build();
List<Corpus> corpus = speechToText.listCorpora(listCorporaOptions)
.execute()
.getCorpora(); // status: 403, error: Forbidden
System.out.println(corpus.get(0));
ошибка:
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[ForbiddenException: Forbidden]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:251)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:178)
at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:363)
at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:361)
at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:413)
at scala.concurrent.Future$$Lambda$6244/000000001ECBEAD0.apply(Unknown Source)
at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
at scala.concurrent.impl.Promise$$Lambda$3716/00000000172D40F0.apply(Unknown Source)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
Caused by: com.ibm.watson.developer_cloud.service.exception.ForbiddenException: Forbidden
at com.ibm.watson.developer_cloud.service.WatsonService.processServiceCall(WatsonService.java:474)
at com.ibm.watson.developer_cloud.service.WatsonService$WatsonServiceCall.execute(WatsonService.java:532)
at controllers.Controller.getCorpora(Controller.java:147)
at router.Routes$$anonfun$routes$1.$anonfun$applyOrElse$52(Routes.scala:1412)
at router.Routes$$anonfun$routes$1$$Lambda$6727/000000001FB17820.apply(Unknown Source)
at play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:134)
at play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:133)
at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$8$$anon$2$$anon$1.invocation(HandlerInvoker.scala:108)
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:88)
at play.http.DefaultActionCreator$1.call(DefaultActionCreator.java:31)