13
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

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

Last updated at Posted at 2019-02-02

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

つまづき

この手順でつまづいた。

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

Command

gcloud auth application-default print-access-token

Error

なんだよこれふざけんな‥! うう 😭

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.

あとでよく見たらちゃんと書いてあった‥よくある例‥がんばれ俺‥

環境変数 GOOGLE_APPLICATION_CREDENTIALS をサービス アカウント キーが含まれる JSON ファイルのファイルパスに設定します。

Credential

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

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

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

13
10
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
13
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?