我正在尝试通过IBM Cloud Java SDK授权我的IBM Cloud语音转文本服务(IAM授权)。尽管我的API密钥和服务URL正确,但是我仍然从服务器获取401 not authorized
。
这是我的代码:
IamOptions iamOptions = new IamOptions.Builder().apiKey("dummy-api-key").url("dummy-url").build();
SpeechToText speechToText = new SpeechToText(iamOptions);
这是服务器响应(日志)
Aug. 09, 2018 10:44:01 PM okhttp3.internal.platform.Platform log
INFO: --> POST https://iam.bluemix.net/identity/token h2 (135-byte body)
Aug. 09, 2018 10:44:02 PM okhttp3.internal.platform.Platform log
INFO: <-- 200 https://iam.bluemix.net/identity/token (181ms, 1759-byte body)
Aug. 09, 2018 10:44:03 PM com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.BaseRecognizeCallback onError
SEVERE: Expected HTTP 101 response but was '401 Not Authorized'
java.net.ProtocolException: Expected HTTP 101 response but was '401 Not Authorized'
at okhttp3.internal.ws.RealWebSocket.checkResponse(RealWebSocket.java:216)
at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:183)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:141)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:844)
我没有包括我的语音合成代码,因为它无关紧要。我已经检查了IBM Java文档和IAM文档。这就是他们指示如何在IBM Cloud中授权的方法。
IBM GitHub页面example
答案 0 :(得分:0)
我知道了。您无需传递url
参数,而是将其设置为端点。
IamOptions iamOptions = new IamOptions.Builder().apiKey("ElPOiM4sMnO4CzJq7LEx1h-4dgaQcCNS1WgGYsnNi59D").build();
SpeechToText speechToText = new SpeechToText(iamOptions);
speechToText.setEndPoint("https://gateway-syd.watsonplatform.net/speech-to-text/api");