如何为 Google Compute Engine 设置 GOOGLE_APPLICATION_CREDENTIALS?
How to set GOOGLE_APPLICATION_CREDENTIALS for Google Compute Engine?
我有 Google Compute Engine 的凭证文件,重命名为 key.json。下一步是设置名称为 GOOGLE_APPLICATION_CREDENTIALS 的环境变量。但它说错误:从环境变量 GOOGLE_APPLICATION_CREDENTIALS 读取凭据文件时出错 ...路径.. 从流中读取凭据时出错,未指定 'type' 字段。
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
GoogleCredential credential = GoogleCredential.getApplicationDefault();
我想知道如何在eclipse中设置变量GOOGLE_APPLICATION_CREDENTIALS?
阅读 documentation 即可解决此问题。截至 2016 年 3 月 15 日:
The environment variable GOOGLE_APPLICATION_CREDENTIALS is checked. If
this variable is specified it should point to a file that defines the
credentials.
文档详细说明了如何创建此类文件。
关于如何在eclipse中设置它,它是一个环境变量,你应该搜索Eclipse文档以了解如何为你想要的任务设置环境变量运行。
您收到错误消息是因为您下载的是 OAuth 2.0 客户端 ID 而不是 Service Account 密钥。
如果您想使用常规用户凭据作为应用程序默认值,您现在可以使用 gcloud beta auth application-default login
命令启动网络 sign-in 流程。这会将它们放在应用程序默认凭据的 well-known 位置,因此如果您使用此方法,则应取消设置 GOOGLE_APPLICATION_CREDENTIALS 变量。
如果您使用的是 tomcat(虽然这在任何情况下都有效),您必须搜索 "launch configuration",在 "environment" 选项卡中您可以添加变量和它的价值。
在图像中,您可以看到我从 tomcat 概览访问了 "launch configuration"。
另一种选择是使用GoogleCredentials.fromStream("path_to_json")来设置凭据,这取决于在可以使用的地方使用api。
我有 Google Compute Engine 的凭证文件,重命名为 key.json。下一步是设置名称为 GOOGLE_APPLICATION_CREDENTIALS 的环境变量。但它说错误:从环境变量 GOOGLE_APPLICATION_CREDENTIALS 读取凭据文件时出错 ...路径.. 从流中读取凭据时出错,未指定 'type' 字段。
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
GoogleCredential credential = GoogleCredential.getApplicationDefault();
我想知道如何在eclipse中设置变量GOOGLE_APPLICATION_CREDENTIALS?
阅读 documentation 即可解决此问题。截至 2016 年 3 月 15 日:
The environment variable GOOGLE_APPLICATION_CREDENTIALS is checked. If this variable is specified it should point to a file that defines the credentials.
文档详细说明了如何创建此类文件。
关于如何在eclipse中设置它,它是一个环境变量,你应该搜索Eclipse文档以了解如何为你想要的任务设置环境变量运行。
您收到错误消息是因为您下载的是 OAuth 2.0 客户端 ID 而不是 Service Account 密钥。
如果您想使用常规用户凭据作为应用程序默认值,您现在可以使用 gcloud beta auth application-default login
命令启动网络 sign-in 流程。这会将它们放在应用程序默认凭据的 well-known 位置,因此如果您使用此方法,则应取消设置 GOOGLE_APPLICATION_CREDENTIALS 变量。
如果您使用的是 tomcat(虽然这在任何情况下都有效),您必须搜索 "launch configuration",在 "environment" 选项卡中您可以添加变量和它的价值。 在图像中,您可以看到我从 tomcat 概览访问了 "launch configuration"。
另一种选择是使用GoogleCredentials.fromStream("path_to_json")来设置凭据,这取决于在可以使用的地方使用api。