2017-07-06 59 views
0

我剛剛創建了一個Face API密鑰,並去了微軟的測試console來測試它,但我得到了無效的密鑰錯誤作爲響應。我無法弄清楚如何將westus改爲westcentralus,所以我放了一個小的PHP代碼來發送請求。同樣的錯誤。下面是代碼:使用Face API時無效的訂閱密鑰

$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

回答

0

您應該更改下面的代碼行:

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

到:

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