I would like to access IBM Tone Analyzer through PHP using CURL, however, I keep getting authorization errors like shown below. The code I use is shown in the code section.
Although looking up numerous help pages and forums, I haven't found a suitable solution. Could someone please help me how to solve this?
Thanks a lot in advance.
With best regards!
This is the code i use:
<?php
//print_r($_POST);
$ch = curl_init();
$file_path = "tone.json";
$url = "https://api.eu-gb.tone-analyzer.watson.cloud.ibm.com/instances/$BLACKENED$/v3/tone?$
$header_args = array(
'Accept: application/json',
'Content-Type: application/json',
'Authorization: Basic apikey:$BLACKENED$'
);
curl_setopt_array($ch,array(CURLOPT_URL => $url, CURLOPT_HEADER => $header_args, CURLOPT_UPLOAD => true, CURLOPT_POST => true, CURLOPT_INFILE => $file_path));
$response = curl_exec($ch);
echo($response);
curl_close($ch);
?>
This is the error i get:
HTTP/1.1 401 Unauthorized strict-transport-security: max-age=31536000; includeSubDomains; WWW-Authenticate: Basic realm="IBM Watson Gateway(Log-in)" Content-Length: 164 Content-Type: application/json x-dp-watson-tran-id: $BLACKENED$ x-request-id: $BLACKENED$ x-global-transaction-id: $BLACKENED$ Server: watson-gateway X-EdgeConnect-MidMile-RTT: 0 X-EdgeConnect-Origin-MEX-Latency: 380 Date: Mon, 06 Dec 2021 21:46:28 GMT Connection: close {"code":401,"more_info":"https://cloud.ibm.com/docs/watson?topic=watson-authorization-error","error":"Unauthorized","trace":"$BLACKENED$"} 1