- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
google docs假设使用服务帐户的 JSON key 的路径导出环境变量 GOOGLE_APPLICATION_CREDENTIALS
,gcloud 将使用它。我无法让它工作。
我的命令是:
GOOGLE_APPLICATION_CREDENTIALS=/home/ubuntu/.config/google-creds.json bq ls
这只会引发一个错误:
You do not currently have an active account selected. Please run:
$ gcloud auth login
to obtain new credentials, or if you have already logged in with a different account:
$ gcloud config set account ACCOUNT
to select an already authenticated account to use.
gcloud -v
给出:
Google Cloud SDK 92.0.0
bq 2.0.18
bq-nix 2.0.18
core 2016.01.12
core-nix 2015.11.24
gcloud
gsutil 4.16
gsutil-nix 4.15
我做错了什么,我该如何解决?我需要 gsutil
和 bq
来使用这个文件。我正在处理多个项目,因此无法激活任何一个。
最佳答案
你试过了吗gcloud auth activate-service-account
?:
gcloud auth activate-service-account --key-file google-creds.json
(似乎命令行工具并没有像 gcloud 在代码中用作库时那样进入整个凭证发现链。)
如果您需要使用多个配置(例如身份验证、项目 ID),您可以设置 configurations .例如,如果您有两个要使用的服务帐户凭据 - 称它们为 sa1.json
和 sa2.json
- 您可以执行以下操作:
$ gcloud config configurations create proj1
$ gcloud config configurations activate proj1
$ gcloud auth activate-service-account --key-file sa1.json
$ gcloud config configurations create proj2
$ gcloud config configurations activate proj2
$ gcloud auth activate-service-account --key-file sa2.json
现在,您可以使用 gcloud config configurations activate
命令来设置您要使用的配置,或者设置 CLOUDSDK_ACTIVE_CONFIG_NAME
环境变量来指定在哪个环境下使用您要运行命令的配置。即使用 sa1.json
cred 运行 bq ls
:
$ CLOUDSDK_ACTIVE_CONFIG_NAME=proj1 bq ls
对于 sa2.json
信誉:
$ CLOUDSDK_ACTIVE_CONFIG_NAME=proj2 bq ls
关于python - 为什么导出 GOOGLE_APPLICATION_CREDENTIALS 不适用于 `bq`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34905714/
我是一名优秀的程序员,十分优秀!