Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request had invalid authentication credentials. Expected OAuth 2 access token error in cloud speech api

Tags:

i have followed the google cloud speech api quickstart of requesting api by using

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 

and following link but i got error of

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

What should i do now?

Thanx in advance

like image 865
Patel Avatar asked Feb 10 '18 11:02

Patel


People also ask

What is access token in API?

What is an Access Token? A credential that can be used by an application to access an API. Access Tokens can be either an opaque string or a JSON Web Token (JWT) . They inform the API that the bearer of the token has been authorized: to access a particular service or services.


2 Answers

It could be that The Application Default Credentials are not available

Try to login by running

gcloud auth application-default login 

And follow the instructions, reference: gcloud auth application-default login

If you want to make sure the authentication process went well, run:

gcloud auth application-default print-access-token 

You should see an access token, reference gcloud auth application-default print-access-token

like image 53
Samir Aleido Avatar answered Sep 18 '22 12:09

Samir Aleido


I fixed the problem by logging out, and logging in to agree to some new terms and conditions google have made since last time I used google clouds (firebase in my case).

like image 42
Asbis Avatar answered Sep 19 '22 12:09

Asbis