0
votes

I'm trying to follow this guide https://cloud.google.com/speech/docs/getting-started to call GAE speech to text api through curl. But it doesn't seem to work.

I've setup a project and enabled speech to text api. But then when I try to active the service account it fails. I've run diagnostics, tried different accounts, verified the json file (has email), tried gcloud beta init :-(

bash-3.2$ gcloud auth activate-service-account [email protected] --key-file=project.json ERROR: (gcloud.auth.activate-service-account) Failed to activate the given service account. Please ensure provided key file is valid.

The next step though 'gcloud auth print-access-token' returns a token.

But the final step (curl) returns this -

{ "error": { "code": 403, "message": "Google Cloud Speech API has not been used in project google.com:cloudsdktool before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/speech.googleapis.com/overview?project=google.com:cloudsdktool then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.", "status": "PERMISSION_DENIED", "details": [ { "@type": "type.googleapis.com/google.rpc.Help", "links": [ { "description": "Google developers console API activation", "url": "https://console.developers.google.com/apis/api/speech.googleapis.com/overview?project=google.com:cloudsdktool" } ] } ] } }

The problem seems to lie in the project(google.com:cloudsdktool instead of mine) used to authenticate the incoming request.

I'm guessing the call to activate-service-account is causing this?

1

1 Answers

5
votes

You are getting the error message for google.com:cloudsdktool project because the command you ran with curl gcloud auth print-access-token was using your user account credentials (created by gcloud auth login) and not service account (as you point out that step failed for you).

The command to activate service account is correct (btw you do not need to provide the account, as one from the file will be used)

$ gcloud auth activate-service-account --key-file=project.json

Make sure your project.json is correct file in the right format format. You can create this json key file either in

  1. in https://console.cloud.google.com/iam-admin/serviceaccounts/project?project=YOUR_PROJECT_NAME
  2. gcloud iam service-accounts keys create, see reference guide.

The file will look like

{
  "private_key_id": "....",
  "private_key": "-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----\n",
  "client_email": "...",
  "client_id": "...",
  "type": "service_account"
}

Note that client_email will be used for ACCOUNT in activate-service-account command.