如何获取IBM Watson STT服务的认证令牌? [英] How to get the authentication token for IBM watson STT service?

查看:132
本文介绍了如何获取IBM Watson STT服务的认证令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Watson语音转文本服务,根据

I am trying to use the Watson Speech To Text service which needs the following command for the websocket Interface as per the documentation

var token = {authentication-token};
var wsURI = 'wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize'
+ '?watson-token=' + token
+ '&model=es-ES_BroadbandModel';

我已经尝试过使用终端上的curl命令获取{authentication-token}

I have tried this to get the {authentication-token} using curl command on terminal

curl -X GET --user "apikey:{apikey}" "https://stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/text-to-speech/api"

上面的命令产生

错误:{代码":401,错误":未经授权",描述":"ERCD250-LDAP-DN-AUTHERR"}

Error: {"code":401,"error":"Unauthorized","description":"ERCD250-LDAP-DN-AUTHERR"}

找不到适合的文档,包括在

Couldn't find proper documentation for this including several posts which seem to be out of scope after the recent changes made by IBM watson team.

问题:如何获得authentication-token以便正确连接到Watson Web套接字?

Question: How do I get the authentication-token for connecting to the watson web socket properly?

推荐答案

要获取authentication-token,您需要运行以下 cURL命令.可以在连接之前将其包含在您的程序中(Websocket握手).

To get the authentication-token you need to run the following cURL command. This can be included in your program prior to the connection (websocket handshake).

curl -k -X POST --header "Content-Type: application/x-www-form-urlencoded" --header "Accept: application/json" --data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" --data-urlencode "apikey={your apikey}" "https://iam.bluemix.net/identity/token"

点击此链接了解更多详细信息- https://console.bluemix.net/docs/services/watson/getting-started-iam.html

Follow this link for more details - https://console.bluemix.net/docs/services/watson/getting-started-iam.html

对于C ++用户-您可以按以下内容添加

For C++ users - You may include this as below

#include <curl/curl.h>

main(){
    //step 1- Initialise curl library
    //step 2- Set header
              curl_slist_append(headers,"Accept: application/json");
    //step 3- Set Post request data
              curl_slist_append(postdata,"grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey={my apikey}");
    //step 4- setup cURL request
          curl_easy_setopt(curl, CURLOPT_URL,"https://iam.bluemix.net/identity/token");
          curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
          curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postdata);
/*Write callbacks to use the response in your authentication*/

          res = curl_easy_perform(curl);

    curl_slist_free_all(headers);
    // always cleanup
    curl_easy_cleanup(curl);

回调内取一个变量token来保存解析后的响应

inside callback take a variable token to hold the parsed response

token = "Bearer<space><ParsedResponse>";

此字符串应用作 websoket握手

这篇关于如何获取IBM Watson STT服务的认证令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆