我想獲取Microsoft Translator API的身份驗證令牌。這是我的代碼:如何獲取Microsoft Translator API的身份驗證令牌?
<?php
//1. initialize cURL
$ch = curl_init();
//2. set options
//Set to POST request
curl_setopt($ch, CURLOPT_POST,1);
// URL to send the request to
curl_setopt($ch, CURLOPT_URL, 'https://api.cognitive.microsoft.com/sts/v1.0/issueToken');
//return instead of outputting directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//whether to include header in the output. here set to false
curl_setopt($ch, CURLOPT_HEADER, 0);
//pass my subscription key
curl_setopt($ch, CURLOPT_POSTFIELDS,array(Subscription-Key => '<my-key>'));
//CURLOPT_SSL_VERIFYPEER- Set to false to stop verifying certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//3. Execute the request and fetch the response. check for errors
$output = curl_exec($ch);
if ($output === FALSE) {
echo "cURL Error" . curl_error($ch);
}
//4. close and free up the curl handle
curl_close($ch);
//5. display raw output
print_r($output);
?>
它給了我下面的錯誤: {「的StatusCode」:401,「消息」:「由於缺少訂閱密鑰拒絕訪問確保發出請求時,包括訂閱密鑰一個API「。 }
這可能意味着密鑰根據下面的網站無效,但我確保密鑰在同一網站上有效。
http://docs.microsofttranslator.com/oauth-token.html
我做了網上關於如何讓Authenticationtoken找到一些例子,但它們已經過時。
我怎樣才能獲得AuthenticationToken /實現微軟認識我的鑰匙?