google-cloud-platformgoogle-apigoogle-oauthgoogle-oauth-java-client

Code 403 : “The request is missing a valid API key.” PERMISSION_DENIED Service Account Key Google Cloud speech to text api in python"


I want to implement the Google Cloud speech to text using a service account. What i have try is i have set the environment variable to that json and send the post request to this url 'https://speech.googleapis.com/v1/speech:longrunningrecognize'.

Code: req = requests.post(url, data={ "audio":{ "content":enc }, "config":{ "audioChannelCount":2, "enableSeparateRecognitionPerChannel":True, "enableWordTimeOffsets":True, "diarizationConfig":{ "enableSpeakerDiarization": True, "minSpeakerCount": 1, "maxSpeakerCount": 2 },

}}) Error: 403 { "error": { "code": 403, "message": "The request is missing a valid API key.", "status": "PERMISSION_DENIED" } }


Solution

  • The error message indicates that you are not authenticating correctly. The way to do this is to pass an authentication token as a Bearer Token header in your request.

    The following documentation explains how to generate the required credentials and pass them with the request, this provides an overview of service accounts Service accounts overview

    Creating a service account instructions Creating service accounts

    Once you have created the service account you generate the credentials which are stored in json format, these are then passed as a Bearer Token