我试图从cloud.googe.com中执行一些示例代码,将一个示例音频文件转换为文本,但是我得到了一个错误消息,这是没有意义的。
我已经经历了所有的步骤:
export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
(路径是我下载的JSON文件的位置)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
因此,我没有得到教程页面上说我会得到的响应,而是得到一条不在GCP的帮助页面上的错误消息:
ERROR: (gcloud.auth.application-default.print-access-token) File /pathofFile/nameofFile.json (pointed by GOOGLE_APPLICATION_CREDENTIALS environment variable) does not exist!
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"status": "PERMISSION_DENIED"
}
}
这个错误显然不是因为我没有设置环境变量,因为错误消息写着“(由GOOGLE_APPLICATION_CREDENTIALS环境变量指出)”,并且错误消息显示正确的JSON凭据文件的正确路径。JSON凭据文件肯定在那里;我可以在finder中看到它。
这里有什么问题吗?
编辑:当我尝试运行gcloud auth application-default login
或gcloud auth application-default print-access-token
时,我得到了错误消息gcloud: command not found
所以看起来我没有完全安装Cloud。现在,我想知道我需要安装哪个SDK组件才能完成这个任务。我需要安装下列哪一项?
The latest available version is: 246.0.0
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Components │
├──────────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤
│ Status │ Name │ ID │ Size │
├──────────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤
│ Update Available │ BigQuery Command Line Tool │ bq │ < 1 MiB │
│ Update Available │ Cloud SDK Core Libraries │ core │ 10.5 MiB │
│ Not Installed │ App Engine Go Extensions │ app-engine-go │ 56.4 MiB │
│ Not Installed │ Cloud Bigtable Command Line Tool │ cbt │ 6.3 MiB │
│ Not Installed │ Cloud Bigtable Emulator │ bigtable │ 5.6 MiB │
│ Not Installed │ Cloud Datalab Command Line Tool │ datalab │ < 1 MiB │
│ Not Installed │ Cloud Datastore Emulator │ cloud-datastore-emulator │ 18.4 MiB │
│ Not Installed │ Cloud Datastore Emulator (Legacy) │ gcd-emulator │ 38.1 MiB │
│ Not Installed │ Cloud Firestore Emulator │ cloud-firestore-emulator │ 40.5 MiB │
│ Not Installed │ Cloud Pub/Sub Emulator │ pubsub-emulator │ 34.8 MiB │
│ Not Installed │ Cloud SQL Proxy │ cloud_sql_proxy │ 3.7 MiB │
│ Not Installed │ Emulator Reverse Proxy │ emulator-reverse-proxy │ 14.5 MiB │
│ Not Installed │ Google Cloud Build Local Builder │ cloud-build-local │ 5.9 MiB │
│ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr │ 1.8 MiB │
│ Not Installed │ gcloud Alpha Commands │ alpha │ < 1 MiB │
│ Not Installed │ gcloud Beta Commands │ beta │ < 1 MiB │
│ Not Installed │ gcloud app Java Extensions │ app-engine-java │ 105.6 MiB │
│ Not Installed │ gcloud app PHP Extensions │ app-engine-php │ 21.9 MiB │
│ Not Installed │ gcloud app Python Extensions │ app-engine-python │ 6.0 MiB │
│ Not Installed │ gcloud app Python Extensions (Extra Libraries) │ app-engine-python-extras │ 28.5 MiB │
│ Not Installed │ kubectl │ kubectl │ < 1 MiB │
│ Installed │ Cloud Storage Command Line Tool │ gsutil │ 3.8 MiB │
└──────────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘
To install or remove components at your current SDK version [245.0.0], run:
$ gcloud components install COMPONENT_ID
$ gcloud components remove COMPONENT_ID
编辑:非常感谢大家的帮助。最后我重新安装了SDK。在安装SDK之前,首先下载文件,然后运行./google-cloud-sdk/install.sh
但是这次我删除了我电脑上的所有SDK文件,并运行了curl https://sdk.cloud.google.com | bash
。除此之外,我确保将“google”目录保存到我的根目录中,这样我就可以使用默认的.rc文件路径了。
发布于 2019-05-14 00:34:33
cURL命令使用gcloud工具进行身份验证:gcloud auth application-default print-access-token
。由于您使用本地机器来运行或提交API请求,因此需要在您的计算机中使用安装并初始化Cloud (MAC)来利用gcloud工具。
https://stackoverflow.com/questions/56082773
复制