How to get the authentication token for IBM watson STT service?

前端 未结 2 778
忘了有多久
忘了有多久 2021-01-07 03:56

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 = {auth         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-07 04:27

    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"
    

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

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

    #include 
    
    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);
    

    inside callback take a variable token to hold the parsed response

    token = "Bearer";
    

    This string should be used as the request header for websoket handshake

提交回复
热议问题