我想获取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 /实现微软认识我的钥匙?