Watson Developer java-sdk STT

时间:2017-09-26 19:11:16

标签: android ibm-cloud watson language-translation

在示例应用中获取此错误。

  

java.net.ProtocolException:预期的HTTP 101响应但是为'401   未授权'

使用此代码段进行转换。

TranslateOptions translateOptions = new TranslateOptions.Builder()
                             .addText(params[0])
                             .source(Language.ENGLISH)
                             .target(selectedTargetLanguage)
                             .build();

TranslationResult translationResult = translationService
                             .translate(translateOptions)
                             .execute();

执行应用程序崩溃后,我在日志中看到此错误。

D/OkHttp: --> POST https://gateway.watsonplatform.net/language-translator/api/v2/translate/v2/translate http/1.1 (46-byte body)
D/OkHttp: <-- 401 Not Authorized https://gateway.watsonplatform.net/language-translator/api/v2/translate/v2/translate (413ms, unknown-length body)

POST https://gateway.watsonplatform.net/language-translator/api/v2/translate/v2/translate, status: 401, error: Not Authorized

--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
Process: com.gobiggi.watsontutorial, PID: 10136

java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:325)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)

Caused by:

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

at com.ibm.watson.developer_cloud.service.WatsonService.processServiceCall(WatsonService.java:410)
at com.ibm.watson.developer_cloud.service.WatsonService$1.execute(WatsonService.java:174)
at com.gobiggi.watsontutorial.MainActivity$TranslationTask.doInBackground(MainActivity.java:328)
at com.gobiggi.watsontutorial.MainActivity$TranslationTask.doInBackground(MainActivity.java:321)
at android.os.AsyncTask$2.call(AsyncTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
at java.lang.Thread.run(Thread.java:761)

1 个答案:

答案 0 :(得分:0)

我不太了解watson sdk是如何工作的,只是看看我看到的错误:

  

com.ibm.watson.developer_cloud.service.exception.UnauthorizedException:   未经授权:由于凭据无效,访问被拒绝。提示:没有   你设置了端点?

表示提供的凭据无效。你应该先看一下。