MS Translator Text APIを使うために、PHPファイルからTokenを得ようとしています。
下記のコードを書いたのですが、bool<false>が戻ってきてしまいます。
仕様は下記のURLにあり、PHPファイルのどこがおかしいのでしょうか。
http://docs.microsofttranslator.com/oauth-token.html
教えていただければありがたいです。
なお、xxxxxの部分は、実際にはキーとなります。
<?php $url = 'https://api.cognitive.microsoft.com/sts/v1.0/issueToken'; $data = array('Subscription-Key' => 'xxxxxxxxxxxxxxxxxx'); $content = http_build_query($data); $options = array('http' => array( 'method' => 'post', 'content' => $content, )); $contents = file_get_contents($url, false, stream_context_create($options)); var_dump($contents); ?>
An authentication token is required for every call to the Microsoft Translator Text or Speech API. After subscribing to a Translator offer in the Microsoft Cognitive Services, locate your subscription key in the Azure management portal. Then, pass your subscription key to the token service to obtain a valid token.
The URL of the token service is https://api.cognitive.microsoft.com/sts/v1.0/issueToken.
The subscription key is passed to the service via request header Ocp-Apim-Subscription-Key or in the query string with query parameter Subscription-Key.
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/14 14:08
2017/07/14 16:06