Microsoft Translator API用の認証トークンを取得したいとします。 、「メッセージ」401: {「からstatusCode」:それは私に次のエラーを与える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);
?>
:これは私のコードです。サブスクリプションキーが欠落が原因で拒否された「アクセスに要求を行うときにサブスクリプションキーが含まれていることを確認しますAPI。 " }
これは、以下のウェブサイトではキーが無効である可能性がありますが、そのキーが同じウェブサイトで有効であることを保証しています。
http://docs.microsofttranslator.com/oauth-token.html
私はオンラインAuthenticationtokenを取得する方法についていくつかの例を見つけたが、彼らは時代遅れです。
AuthenticationTokenを取得するにはどうすればいいですか?Microsoftが自分のキーを認識するためにはどうすればよいですか?