简体   繁体   English

错误:7 PERMISSION_DENIED:您的应用程序已使用来自 Google Cloud SDK 的最终用户凭据进行了身份验证

[英]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.几个月前这在我的 websocket 服务器内部没有代码更改的情况下工作,但是今天使用它似乎 Google speech to text api 不再允许使用访问令牌进行身份验证。

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这反而给我带来了这个美丽的错误,即使此时环境是用项目 ID 设置的

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

Any help in resolving this would be much appreciated!解决此问题的任何帮助将不胜感激!

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);

I was able to follow the Official Quickstart and got it working by using Client Libraries with no issues.我能够按照官方快速入门进行操作,并通过使用客户端库使其正常工作,没有任何问题。 I will explain what I did right below.我将在下面解释我所做的。

From Cloud Speech-to-Text - Quickstart :来自Cloud Speech-to-Text - 快速入门

  1. Create or select a project:创建或选择项目:

    gcloud config set project YOUR_PROJECT_NAME

  2. Enable the Cloud Speech-to-Text API for the current project:为当前项目启用 Cloud Speech-to-Text API:

    gcloud services enable speech.googleapis.com

  3. Create a service account:创建服务帐户:

    gcloud iam service-accounts create [SA-NAME] \ --description "[SA-DESCRIPTION]" \ --display-name "[SA-DISPLAY-NAME]"

  4. Download a private key as JSON:下载私钥作为 JSON:

    gcloud iam service-accounts keys create ~/key.json \ --iam-account [SA-NAME]@[PROJECT-ID].iam.gserviceaccount.com

  5. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key:将环境变量GOOGLE_APPLICATION_CREDENTIALS设置为包含您的服务帐户密钥的 JSON 文件的文件路径:

    export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"


  1. Install the Client Library安装客户端库

    npm install --save @google-cloud/speech

  2. Created a quickstart.js file and put the following code sample inside:创建一个quickstart.js文件并将以下代码示例放入其中:

    'use strict';

    // [START speech_quickstart] async function main() { // Imports the Google Cloud client library const speech = require('@google-cloud/speech'); const fs = require('fs');

    // Creates a client const client = new speech.SpeechClient();

    // The name of the audio file to transcribe const fileName = './resources/audio.raw';

    // Reads a local audio file and converts it to base64 const file = fs.readFileSync(fileName); const audioBytes = file.toString('base64');

    // The audio file's encoding, sample rate in hertz, and BCP-47 language code const audio = { content: audioBytes, }; const config = { encoding: 'LINEAR16', sampleRateHertz: 16000, languageCode: 'en-US', }; const request = { audio: audio, config: config, };

    // Detects speech in the audio file const [response] = await client.recognize(request); const transcription = response.results.map(result => result.alternatives[0].transcript).join('\n'); console.log("Transcription: ${transcription}"); } main().catch(console.error);

WHERE const fileName = './resources/audio.raw' is the path where your test.raw audio is located. WHERE const fileName = './resources/audio.raw'是您的 test.raw 音频所在的路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Cloud Source Repository:远程:PERMISSION_DENIED:调用者没有远程权限 - Google Cloud Source Repository: remote: PERMISSION_DENIED: The caller does not have permission remote Google Cloud Translate V3 Java - PERMISSION_DENIED:Cloud IAM 权限“cloudtranslate.generalModels.predict”被拒绝 - Google Cloud Translate V3 Java - PERMISSION_DENIED: Cloud IAM permission 'cloudtranslate.generalModels.predict' denied 谷歌云翻译权限被拒绝 - 但有作用 - Google Cloud Translation Permission Denied - But has role Firebase Cloud Functions Firestore 触发器产生:错误:7 PERMISSION_DENIED:权限缺失或不足 - Firebase Cloud Functions Firestore Trigger produces: Error: 7 PERMISSION_DENIED: Missing or insufficient permissions Firestore PERMISSION_DENIED - Firestore PERMISSION_DENIED 尝试使用 Ionic4 和 Angular 6 将文档添加到 firebase 时出错 - 错误:PERMISSION_DENIED:权限被拒绝 - Getting error when trying to add document to firebase using Ionic4 and Angular 6 - Error: PERMISSION_DENIED: Permission denied PERMISSION_DENIED:Cloud IAM 权限“cloudtranslate.generalModels.predict”被拒绝 - PERMISSION_DENIED: Cloud IAM permission 'cloudtranslate.generalModels.predict' denied 从云调度程序调用谷歌云 function 时获取权限被拒绝错误 - Getting permission denied error when calling Google cloud function from Cloud scheduler Cloud Build 无法触发构建:generic::permission_denied:权限被拒绝 - Cloud Build Failed to trigger build: generic::permission_denied: Permission denied PERMISSION_DENIED Firestore 模拟器 - PERMISSION_DENIED Firestore Emulator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM