使用人脸时无效的订阅密钥 API
Invalid Subscription key when using Face API
我刚刚创建了一个 Face API 密钥并去 Microsoft 的测试 console 进行了测试,但我收到无效密钥错误作为响应。我不知道如何将 westus 更改为 westcentralus,所以我整理了一个小的 PHP 代码来发送请求。同样的错误。这是代码:
$postData = array(
'url' => '...url to image..',
);
// Setup cURL
$ch = curl_init('https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender');
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
'Ocp-Apim-Subscription-Key' => '9******************************6',
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode($postData)
));
// Send the request
$response = curl_exec($ch);
您应该更改以下代码行:
'Ocp-Apim-Subscription-Key' => '9******************************6',
至:
'Ocp-Apim-Subscription-Key: 9******************************6',
我刚刚创建了一个 Face API 密钥并去 Microsoft 的测试 console 进行了测试,但我收到无效密钥错误作为响应。我不知道如何将 westus 更改为 westcentralus,所以我整理了一个小的 PHP 代码来发送请求。同样的错误。这是代码:
$postData = array(
'url' => '...url to image..',
);
// Setup cURL
$ch = curl_init('https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender');
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
'Ocp-Apim-Subscription-Key' => '9******************************6',
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode($postData)
));
// Send the request
$response = curl_exec($ch);
您应该更改以下代码行:
'Ocp-Apim-Subscription-Key' => '9******************************6',
至:
'Ocp-Apim-Subscription-Key: 9******************************6',