javascriptsocketsoauthgcloudgoogle-speech-api

Error: 7 PERMISSION_DENIED: Your application has authenticated using end user credentials from the Google Cloud SDK


This was working a couple months ago without code changes inside of my websocket server, however using it today it seems that the Google speech to text api no longer allows authentication using access tokens.

This was my previously working method until I hit this error today

const client = new speech.SpeechClient({
   access_token: ACCESS_TOKEN,
   projectId: 'project-name'
});

That nets me the above error in the title.

I also tried switching to a service account (which I used in the past) by setting up the environment as follows

export GOOGLE_APPLICATION_CREDENTIALS="path-to-key.json"

I then run the client without the above code and instead run:

const client = new speech.SpeechClient();

and that nets me this beautiful error instead, even though the environment is set at this point with the project Id

Error: Unable to detect a Project Id in the current environment.

Any help in resolving this would be much appreciated!


Solution

  • I resolved the environment problem and subsequent error by doing the following:

    const options = {
      keyFilename: 'path-to-key.json',
      projectId: 'project-name',
    };
    
    const client = new speech.SpeechClient(options);