GOOGLE_APPLICATION_CREDENTIALS错误 [英] GOOGLE_APPLICATION_CREDENTIALS error

查看:2438
本文介绍了GOOGLE_APPLICATION_CREDENTIALS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用google语音API将音频文件转换为文本,但面临文档中的一些问题。我启用了语音API并创建了一个服务帐户文件。我还获得了激活的服务帐户凭据。然后,我编写了以下命令以使用我的服务帐户来检索授权令牌。

gcloud auth application-default打印访问令牌



但它会返回此消息



我不明白为什么会发生这种情况,因为我已经在计算引擎中创建了一个VM实例。任何人都可以解释我在哪里错了吗?此外,还有其他方法可以验证我的帐户并调用Google语音API吗?

解决方案

gcloud credentials and and application default credentials分开管理。如果您激活了服务帐户密钥文件,那么它只能用于gcloud命令,而不能用于应用程序默认凭证。

gcloud auth application-default 一组命令仅用于管理应用程序默认值,并且与 gcloud auth 中的命令无关。

有几种方法可以激活应用程序默认凭据:


  • 使用您的用户帐户


    • 运行 gcloud auth applocation-default login




    • 设置环境变量 GOOGLE_APPLICATION_CREDENTIALS =路径/到使用服务帐户(首选)

      /your/service_accont_key_file.json

    • copy path / to / your / service_accont_key_file.json to〜/ .config / gcloud / application_default_credentials.json`




      • 在windows上,这可能会有所不同,运行

          gcloud info --format =值(config.paths.global_config_dir)

        获取到您的配置目录的路径。






  gcloud auth application-default print-access-token 

应该有效。


I am trying to use the google speech API for converting an audio file to text, but facing some problems with the documentation.I have enabled the speech API and created an service account file. I also got the service account credentials activated. Then I wrote the following command to retrieve the authorization token using my service account.

gcloud auth application-default print-access-token

But it is returning this message

I don't understand why this is happening because I already have an VM instance created in my Compute Engine. Can anybody explain where am I going wrong with this? Also, is there any other way to authenticate my account and call the google speech API?

解决方案

gcloud credentials and and application default credentials are managed separately. If you activated service account key file this only can be used for gcloud commands but not for application default credentials.

gcloud auth application-default set of commands are there only to manage application default and having nothing to do with commands in gcloud auth.

There a few ways to "activate" application default credentials:

  • Use your user account
    • Run gcloud auth applocation-default login, or
  • Use service account (preferred)

    • set environment variable GOOGLE_APPLICATION_CREDENTIALS=path/to/your/service_accont_key_file.json
    • copy path/to/your/service_accont_key_file.json to ~/.config/gcloud/application_default_credentials.json`

      • On windows this might be different, run

        gcloud info --format="value(config.paths.global_config_dir)"
        

        to get a path to your config directory.

now command like

gcloud auth application-default print-access-token

should work.

这篇关于GOOGLE_APPLICATION_CREDENTIALS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆