Jochen
Jochen

Reputation: 1

How do I make gcloud select the right project?

I am using gcloud to realize speech2text. I had to reset my server and now have trouble getting gcloud recognize the right project.

transscript=$(curl -s -H "Content-Type: application/json" -H "Authorization: Bearer "$(gcloud auth print-access-token) https://speech.googleapis.com/v1/speech:recognize -d @$mailpath/sync_request.json)

results in

"code": 403, "message": "Cloud Speech-to-Text API has not been used in project 32555940559 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/speech.googleapis.com/overview?project= then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",

I have no clue where the wrong project number comes from.

I have tried gcloud config configurations list and the correct project is shown. I have completely deinstalled the sdk. I have assigned GOOGLE_APPLICATION_CREDENTIALS environment variable

all without success.

expected result is assigned correct project

Upvotes: 0

Views: 572

Answers (2)

Jofre
Jofre

Reputation: 3898

You are using the undocumented (and un-recommended) gcloud auth print-access-token. This will use the default SDK client ID (which I'm guessing is in project 32555940559), and the Speech API is not enabled in that project.

As Martin suggested, instead of using gcloud auth print-access-token you should use gcloud auth application-default print-access-token.

You can check if I'm right regarding the client ID by running grep -r 'CLOUDSDK_CLIENT_ID =' $(dirname $(which gcloud))/../ (I just checked and, indeed, that project ID is the project for the default client ID).

Upvotes: 1

Martin Zeitler
Martin Zeitler

Reputation: 76649

as the documentation reads:

gcloud auth application-default print-access-token generates and prints an access token for the current Application Default Credential (ADC). The ADC can be specified either by setting the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of a service account key file (JSON) or using gcloud auth application-default login.

Upvotes: 1

Related Questions