Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GOOGLE_APPLICATION_CREDENTIALS error

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 enter image description here

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?

like image 922
JSnow Avatar asked Jul 05 '17 11:07

JSnow


People also ask

What is Application default credentials in GCP?

Application Default Credentials (ADC) ADC is a strategy used by Cloud Client Libraries and Google API Client Libraries to automatically find credentials based on the application environment, and use those credentials to authenticate to Google Cloud APIs.

Where do I get Google application credentials?

Create credentials for a service account These credentials are used by your code to authorize service account actions within your app. To obtain credentials for your service account: In the Google Cloud console, go to Menu menu > IAM & Admin > Service Accounts.


2 Answers

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 application-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.

like image 131
cherba Avatar answered Oct 31 '22 11:10

cherba


As A solution you can Download the GCLOUD console and then RUN this command on console "gcloud auth application-default" login with the gmail account which have the project access and then you will get access of google api which are enabled.

like image 3
Prabhat Yadav Avatar answered Oct 31 '22 09:10

Prabhat Yadav