LoginSignup
2
0

More than 5 years have passed since last update.

Microsoft Translator APIを利用した翻訳

Posted at

Microsoft Azureを利用した翻訳APIについて備忘録として残しておきます。

準備

Translator Text APIを使用するにはMicrosoft Azure上で利用開始の手続きを行う必要があります。年会費が取られますが、初回の1ヶ月は無償利用できます。

Translator Text APIの登録

リソースとか設定値が妥当か不明ですが、適当に名前を付けてサービスを登録
image.png

APIの使い方

無料利用期間中のサブスクリプションキーではアクセストークンが取得出来ず…↓

$ curl "https://api.cognitive.microsoft.com/sts/v1.0/issueToken?Subscription-Key=管理画面で確認できるサブスクリプションキー"  -i -X POST
~
{ "statusCode": 401, "message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription." }

なので、Microsoft Azure管理画面上で生成されるKeyを直接利用するしか手段がない様子です。キーの有効期限が気になりますが。

API仕様はここを参照
例.

$ curl -i "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=ja" \
     -H "Ocp-Apim-Subscription-Key: サブスクリプションキー" \
     -H "Content-Type: application/json" \
     -d "[{'Text':'Hello, what is your name?'}]"
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0