Authentication error when trying to use google cloud speech API

Asked 2 years ago, Updated 2 years ago, 79 views

I'd like to use Google's speech API.

https://cloud.google.com/speech/docs/getting-started?hl=ja

The quick start above has already failed.
Specifically,

in the above quick start documentation.

Use curl to make a speech:syncrecognize request with the output access token and the
configured in Step 1 Passes the filename of the JSON request.

After you run , the expected voice recognition results do not return and an error returns.
The command is

 curl-s-k-H "Content-Type: application/json" - H "Authorization: Bearer access token string "https://speech.googleapis.com/v1beta1/speech:[email protected]

The following error will be returned as a result of throwing

{
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials.Expected OAuth2 access token, login cookie or other valid authentication credential.See https://developers.google.com/identity/sign-in/web/devconsole-project.,
    "status": "UNAUTHENTICATED"
  }
}

I have created a service account key and got an access token, but what's wrong with it?

google-api

2022-09-29 21:35

2 Answers

Expected OAuth2 access token, login cookie or other valid
authentication credential.

As such, did you set OAuth when creating the AccessKey?
The key is specified, but the OAuth credentials are not attached, so I think the error is displayed.

If you want to use it for the time being, create an unlimited key.
GCP console>API Manager>Create credentials>Create credentials>API key
After creating the key, try creating the key by pressing "Close" instead of pressing "Restrict Key"
Then

exportSPEECH_API_KEY=your key
curl-v-X POST-H "Content-Type: application/json" [email protected] "https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=$ {SPEECH_API_KEY}"

(If you want to use Google cloud speech API with OAuth2 authentication instead of using Cloud Speech API for now, please let me know.)


2022-09-29 21:35

Billing was not enabled for the project that issued the access key.No more errors when enabled.

--From the questioner's comment.


2022-09-29 21:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.