简体   繁体   中英

How to set GOOGLE_APPLICATION_CREDENTIALS for Google Compute Engine?

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.

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

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

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

If you want to use regular user credentials as the application default, you can now use the gcloud beta auth application-default login command 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.

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.

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.

从tomcat概述启动配置

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

The environment variable GOOGLE_APPLICATION_CREDENTIALS is checked. If this variable is specified it should point to a file that defines the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM