Google Cloud の認証トークンを gcloud コマンドで取得する。環境変数でサービスアカウントファイルを指定する例。

Google Cloud の認証トークンを gcloud コマンドで取得する。環境変数でサービスアカウントファイルを指定する例。

つまづき

この手順でつまづいた。

クイックスタート  |  Cloud Translation API  |  Google Cloud

Command

gcloud auth application-default print-access-token

Error

なんだよこれふざけんな‥! うう [emoji:33A]

Yumas-MacBook-Air:tmp yumainaura$ gcloud auth application-default
print-access-token
ERROR: (gcloud.auth.application-default.print-access-token) The
Application Default Credentials are not available. They are available
if running in Google Compute Engine. Otherwise, the environment
variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a
file defining the credentials. See
https://developers.google.com/accounts/docs/application-default-credentials
for more information.

Credential

https://console.cloud.google.com/apis/credentials/serviceaccountkey

ここではテストで何やら強い権限を与えてしまうが、テストが終わったら一瞬で消したほうが良いかも。

image

image

再度チャレンジ

上で作ったファイルを環境変数で指定する。 example.json 的な。

$ GOOGLE_APPLICATION_CREDENTIALS=example.json gcloud auth
application-default print-access-token
トークン!トークン!トークン!トークン!トークン!生成!

うまくいった。

喜びのポーズ!!!

image

Ref

The Application Default Credentials are not available · Issue #175 · googleapis/gax-dotnet

https://github.com/YumaInaura/YumaInaura/issues/545