I'm trying to execute some sample code from cloud.googe.com that converts a sample audio file to text, but I'm getting an error message that doesn't make sense.
I've gone through all the steps indicated:
export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
(with path being the location of the JSON file I downloaded)curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
https://speech.googleapis.com/v1/speech:recognize \
-d @sync-request.json
So then, instead of getting the response that the tutorial page says I will get, I get an error message that is not on GCP's help page:
ERROR: (gcloud.auth.application-default.print-access-token) File /pathofFile/nameofFile.json (pointed by GOOGLE_APPLICATION_CREDENTIALS environment variable) does not exist!
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"status": "PERMISSION_DENIED"
}
}
This error is obviously not due to me failing to set the environment variable because the error message says "(pointed by GOOGLE_APPLICATION_CREDENTIALS environment variable)," and the error message is displaying the correct path of the correct JSON credential file. The JSON credential file is for sure there; I can see it in finder.
What could be going wrong here?
Edit: When I tried running
gcloud auth application-default login
or
gcloud auth application-default print-access-token
,
I got the error message gcloud: command not found
So it looks like I didn't have the Cloud SDK fully installed. Now I'm wondering which of the SDK's components I need to install in order to complete this task. Which of the following would I need to install?
The latest available version is: 246.0.0
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Components │
├──────────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤
│ Status │ Name │ ID │ Size │
├──────────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤
│ Update Available │ BigQuery Command Line Tool │ bq │ < 1 MiB │
│ Update Available │ Cloud SDK Core Libraries │ core │ 10.5 MiB │
│ Not Installed │ App Engine Go Extensions │ app-engine-go │ 56.4 MiB │
│ Not Installed │ Cloud Bigtable Command Line Tool │ cbt │ 6.3 MiB │
│ Not Installed │ Cloud Bigtable Emulator │ bigtable │ 5.6 MiB │
│ Not Installed │ Cloud Datalab Command Line Tool │ datalab │ < 1 MiB │
│ Not Installed │ Cloud Datastore Emulator │ cloud-datastore-emulator │ 18.4 MiB │
│ Not Installed │ Cloud Datastore Emulator (Legacy) │ gcd-emulator │ 38.1 MiB │
│ Not Installed │ Cloud Firestore Emulator │ cloud-firestore-emulator │ 40.5 MiB │
│ Not Installed │ Cloud Pub/Sub Emulator │ pubsub-emulator │ 34.8 MiB │
│ Not Installed │ Cloud SQL Proxy │ cloud_sql_proxy │ 3.7 MiB │
│ Not Installed │ Emulator Reverse Proxy │ emulator-reverse-proxy │ 14.5 MiB │
│ Not Installed │ Google Cloud Build Local Builder │ cloud-build-local │ 5.9 MiB │
│ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr │ 1.8 MiB │
│ Not Installed │ gcloud Alpha Commands │ alpha │ < 1 MiB │
│ Not Installed │ gcloud Beta Commands │ beta │ < 1 MiB │
│ Not Installed │ gcloud app Java Extensions │ app-engine-java │ 105.6 MiB │
│ Not Installed │ gcloud app PHP Extensions │ app-engine-php │ 21.9 MiB │
│ Not Installed │ gcloud app Python Extensions │ app-engine-python │ 6.0 MiB │
│ Not Installed │ gcloud app Python Extensions (Extra Libraries) │ app-engine-python-extras │ 28.5 MiB │
│ Not Installed │ kubectl │ kubectl │ < 1 MiB │
│ Installed │ Cloud Storage Command Line Tool │ gsutil │ 3.8 MiB │
└──────────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘
To install or remove components at your current SDK version [245.0.0], run:
$ gcloud components install COMPONENT_ID
$ gcloud components remove COMPONENT_ID
Edit:
Thanks so much for the help everyone. I ended up reinstalling the SDK. Before I had installed the SDK by first downloading the files and then running
./google-cloud-sdk/install.sh
But this time I deleted all of the SDK files on my computer and ran
curl https://sdk.cloud.google.com | bash
Besides that, I made sure to save the "google-cloud-sdk" directory to my root directory, which made it so I could use the default .rc file path.
The cURL command uses gcloud tool for authentication: gcloud auth application-default print-access-token
. Since you're using a local machine to run or submit the API requests, you would need to install and initialize the Cloud SDK (MAC) in your machine to utilize the gcloud tool.