0

我想使用 CURL 通过 PHP 访问 IBM Tone Analyzer,但是,我不断收到如下所示的授权错误。我使用的代码显示在代码部分。

尽管查找了许多帮助页面和论坛,但我还没有找到合适的解决方案。有人可以帮我解决这个问题吗?

提前非常感谢。

最诚挚的问候!

这是我使用的代码:

<?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);

?>

这是我得到的错误:

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

4

0 回答 0