[英]Default credential for app engine project accessing google cloud storage?
I have an app engine project, I want to access my google cloud storage default bucket.我有一个应用程序引擎项目,我想访问我的谷歌云存储默认存储桶。 The first step of getting a Credential object fails, doing the following on a live instance:
获取凭证 object 的第一步失败,在实时实例上执行以下操作:
Credential creds = GoogleCredential.getApplicationDefault();
The exception message I get:我收到的异常消息:
"The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information." “应用程序默认凭据不可用。如果在 Google Compute Engine 中运行,则它们可用。否则,环境变量 GOOGLE_APPLICATION_CREDENTIALS 必须定义为指向定义凭据的文件。请参阅https://developers.google.com/accounts/docs /application-default-credentials了解更多信息。”
The doc here says that production app engine projects should have access to the default credentials?:此处的文档说生产应用程序引擎项目应该有权访问默认凭据?:
https://developers.google.com/identity/protocols/application-default-credentials https://developers.google.com/identity/protocols/application-default-credentials
"3. If you are running in Google App Engine production, the built-in service account associated with the application will be used." “3. 如果您在 Google App Engine 生产环境中运行,将使用与该应用程序关联的内置服务帐户。”
Is there some setup I'm missing?我缺少一些设置吗?
My app engine version (gradle):我的应用引擎版本(gradle):
com.google.appengine:appengine-java-sdk:1.9.18
and google cloud storage lib version:和谷歌云存储库版本:
com.google.apis:google-api-services-storage:v1-rev35-1.20.0
Thanks谢谢
Go to Google Developers Console -> Credentials and create a default service account .json key. 转到Google Developers Console - >凭据并创建默认服务帐户.json密钥。 When you do that, it will download a file like
default-account-credentials.json
for you. 当你这样做时,它会为你下载一个像
default-account-credentials.json
这样的文件。 You must then put that file somewhere in your app engine project. 然后,您必须将该文件放在app引擎项目中的某个位置。 This file will be referenced when you call
您致电时将引用此文件
Credential creds = GoogleCredential.getApplicationDefault();
However, before that works you must set the environmental variable to that files location. 但是,在此之前,您必须将环境变量设置为该文件位置。 To do that open up your
appengine-web.xml
file and put this line into it: 为此,打开你的
appengine-web.xml
文件并将这一行放入其中:
<env-variables>
<env-var name="GOOGLE_APPLICATION_CREDENTIALS"
value="WEB-INF/default-account-credentials.json" />
</env-variables>
Where value
is the path to your .json
creds file you just downloaded. 其中
value
是您刚刚下载的.json
creds文件的路径。
Now it will work. 现在它会起作用。 (your gradle imports are fine)
(你的gradle进口很好)
I am posting this solution to help others like me who still need help with this error.我发布这个解决方案是为了帮助像我这样仍然需要帮助解决这个错误的人。 Install gcloud on your system, select the project you want to use in the gcloud window, and then authenticate yourself using this command in the gcloud window: "gcloud auth application-default login" to generate a file called application_default_credentials.json.
在你的系统上安装gcloud,select你要在gcloud window中使用的项目,然后在gcloud window中使用这个命令验证自己: “gcloud auth application-default login”生成一个名为application_default_credentials.json的文件。 Your program running on the same system will then use this file automatically for authentication.
在同一系统上运行的程序将自动使用此文件进行身份验证。 Follow this link to install gcloud: https://cloud.google.com/docs/authentication/provide-credentials-adc?hl=en_GB
按照此链接安装 gcloud: https://cloud.google.com/docs/authentication/provide-credentials-adc?hl=en_GB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.