1

我刚刚开始开发 GAE Web 应用程序。我正在尝试获取谷歌云存储桶的列表。我从网站上找到了一些代码。

我在网上找到了 3 种方法。

  1. 使用谷歌存储 API

    https://code.google.com/p/google-api-java-client/source/browse/storage-serviceaccount-appengine-sample/src/main/java/com/google/api/client/sample/storage/ appengine/serviceaccount/StorageSample.java?repo=samples&r=f0c6982b3cde8629511346641bfe4bb5eb28d73f

  2. 使用 Json 库

    但是这个示例需要为存储桶配置域验证。

  3. 使用蟒蛇

    我们现有的应用程序是由 gae 为 Java 开发的。我不认为这种 python 方式可以包含在 Java 应用程序中。

然后我想修复 No1 方式。

它显示凭据错误。存储桶目前已授权给所有人(All Authenticated Users)。我想我需要了解凭证的工作原理。我已经阅读了关于 0Auth2 的谷歌开发者页面。我可以找到 bigquery 的示例。如果您有关于凭证和谷歌云存储的示例或好的网站,这将非常有帮助。

错误;

Error: com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential.(Ljava/util/Collection;)V

我在 API 控制台做了什么:

  • 创建客户端 ID(Web 应用程序、服务帐户、已安装的应用程序)

  • 创建简单 API 访问(新服务器密钥、新浏览器密钥)

我在本地机器上做了什么;

  • 使用 gsutil 设置 ACL

我的开发环境

  • eclipse 3.6 helios(日语语言包)

  • 用于日食的 gae java

  • gae 1.8.0

  • 爪哇 1.6.31

  • 谷歌存储API

  • 谷歌客户端库

  • 其他(tomcat,maven)

  • windows 7 英语和日语语言包

4

1 回答 1

2

Your first attempt (number 1) is the best way to focus on getting this to work. The code sample Marc provided uses the built-in App Engine App Identity module to securely identify the App Engine app to other Google APIs: https://developers.google.com/appengine/docs/java/appidentity/#Asserting_Identity_to_Google_APIs

However, there are 2 gotchas to check:

  1. The App Identity module will not work using the local devserver. When running locally there is no way for the local server to securely identity itself to Google production APIs - so you should either look at using a service account with a downloadable key for local testing, or, easiest option (and what I'd recommend for now), is to deploy into a production App Engine environment to test.

  2. Make sure the App Engine service account email address is added to the access control list for the Google Cloud Storage bucket that you are trying to access. Get this email address by looking under the Admin Console (for your App Engine app) -> Application Settings:

Service Account Name: xxxxxxx@appspot.gserviceaccount.com

To add this to a Google Cloud Storage access control list, either add it to the project team for the project that owns the Google Cloud Storage bucket, or, if you're not using the default access control settings, add it directly to an ACL: https://developers.google.com/storage/docs/accesscontrol

Service accounts with downloadable key - use this for local testing if you can't test in a production App Engine environment: https://developers.google.com/accounts/docs/OAuth2ServiceAccount

于 2013-06-07T15:54:50.987 回答