LoginSignup
1
4

More than 5 years have passed since last update.

google cloud translate API

Last updated at Posted at 2017-03-05

クイックスタート

translate-request.json
{
  "q": "The quick brown fox jumped over the lazy dog.",
  "source": "en",
  "target": "es",
  "format": "text"
}

サービスアカウントの認証

gcloud auth activate-service-account --key-file=<path/to/service-account-key.json>

承認トークンを取得

gcloud auth print-access-token

リクエスト発行

curl -s -k -H Content-Type: application/json" \
    -H "Authorization: Bearer <access_token>" \
    https://translation.googleapis.com/language/translate/v2 \
    -d @translate-request.json

結果

{
  "data": {
    "translations": [
      {
        "translatedText": "El zorro rápida saltó sobre el perro perezoso."
      }
    ]
  }
}

日本語に変換してみた

translate-request.json
{
  "q": "The quick brown fox jumped over the lazy dog.",
  "source": "en",
  "target": "ja",
  "format": "text"
}

結果

{
  "data": {
    "translations": [
      {
        "translatedText": "速い茶色のキツネが怠惰な犬を飛び越えました。"
      }
    ]
  }
}
1
4
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
1
4