Search code examples
phpazureface-api

Invalid Subscription key when using Face API


I've just created a Face API key and went to Microsoft's test console to test it out but I get invalid key error as response. I could not figure out how to change westus to westcentralus so I put together a small PHP code to send the request. The same error. Here is the code:

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

enter image description here


Solution

  • You should change the following line of code:

    'Ocp-Apim-Subscription-Key' => '9******************************6', 
    

    to:

    'Ocp-Apim-Subscription-Key: 9******************************6',