eclipse 如何为 Google Compute Engine 设置 GOOGLE_APPLICATION_CREDENTIALS?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35629641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:04:18  来源:igfitidea点击:

How to set GOOGLE_APPLICATION_CREDENTIALS for Google Compute Engine?

javaeclipsegoogle-compute-engine

提问by Aakash Parashar

I have Google Compute Engine's Credentials file , renamed as key.json. The next step is to set the environment variable with name GOOGLE_APPLICATION_CREDENTIALS. But it says error: Error reading credential file from environment variable GOOGLE_APPLICATION_CREDENTIALS ...path.. Error reading credentials from stream, 'type' field not specified.

我有 Google Compute Engine's Credentials 文件,重命名为 key.json。下一步是设置名为 GOOGLE_APPLICATION_CREDENTIALS 的环境变量。但它说错误:从环境变量 GOOGLE_APPLICATION_CREDENTIALS ...路径读取凭据文件时出错。从流中读取凭据时出错,未指定“类型”字段。

httpTransport = GoogleNetHttpTransport.newTrustedTransport(); GoogleCredential credential = GoogleCredential.getApplicationDefault();

httpTransport = GoogleNetHttpTransport.newTrustedTransport(); GoogleCredential credential = GoogleCredential.getApplicationDefault();

I want to know how to set variable GOOGLE_APPLICATION_CREDENTIALS in eclipse?

我想知道如何在eclipse中设置变量GOOGLE_APPLICATION_CREDENTIALS?

采纳答案by Adam

You got the error because you downloaded an OAuth 2.0 Client ID instead of a Service Accountkey.

您收到错误是因为您下载的是 OAuth 2.0 客户端 ID 而不是服务帐户密钥。

If you want to use regular user credentials as the application default, you can now use the gcloud beta auth application-default logincommand to launch the web sign-in flow. This puts them in the well-known location for application default credentials, so you should unset the GOOGLE_APPLICATION_CREDENTIALS variable if you use this method.

如果要使用常规用户凭据作为应用程序默认值,现在可以使用该gcloud beta auth application-default login命令启动 Web 登录流程。这会将它们放在应用程序默认凭据的众所周知的位置,因此如果您使用此方法,您应该取消设置 GOOGLE_APPLICATION_CREDENTIALS 变量。

回答by Edgardo Genini

If you are using a tomcat (although this is valid in any case), you have to search for "launch configuration", in the "environment" tab you can add the variable and its value. In the image you can see that I accessed "launch configuration" from the tomcat overview.

如果您使用的是 tomcat(尽管这在任何情况下都有效),您必须搜索“启动配置”,在“环境”选项卡中您可以添加变量及其值。在图像中,您可以看到我从 tomcat 概览中访问了“启动配置”。

Another option is to use GoogleCredentials.fromStream ("path_to_json") to set the credentials, depending on which api is used where it can be used.

另一种选择是使用 GoogleCredentials.fromStream ("path_to_json") 来设置凭据,具体取决于在可以使用的地方使用哪个 api。

launch configuration from tomcat overview

从 tomcat 概览启动配置

回答by Nick

This question is satisfiable by a reading of the documentation. As of Mar. 15, 2016:

这个问题可以通过阅读文档来满足。截至 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.

检查环境变量 GOOGLE_APPLICATION_CREDENTIALS。如果指定了这个变量,它应该指向一个定义凭证的文件。

The documentation explains more about how you can create such a file.

该文档解释了有关如何创建此类文件的更多信息。

As to how to set this in eclipse, it's an environment variable, and you should search the Eclipse documentation to see how to set environment variables for tasks you want to run.

至于如何在eclipse中设置它,它是一个环境变量,您应该搜索Eclipse文档以了解如何为要运行的任务设置环境变量。