我需要使用 Google App Engine 中的 Google 云存储。为此,我尝试使用应用程序默认凭据来获取授权凭据以连接到 Cloud Storage API。我使用 add Google Api 选项在 eclipse 中添加了 Google Cloud Storage JSON API。它添加了 google-api-client-1.18.0-rc.jar。这个jar没有下面的方法。
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
当我看到示例时,我看到下面的依赖项
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-storagetransfer</artifactId>
<version>v1-rev1-1.20.0</version>
</dependency>
但是在 Eclipse 中,在使用添加 Google API 窗口时,我没有找到找到此“v1-rev1-1.20.0”版本的 Google Cloud Storage API 的方法。如何下载与 v1-rev1-1.20.0 版本兼容的 Google Cloud Storage API jar?
最佳答案
由于您是从 App Engine 访问 Cloud Storage,因此您可以使用为 App Engine 构建的 GCS 客户端:
GcsService gcsService = GcsServiceFactory.createGcsService();
// ...
ListResult objects = fileService.list(MY_BUCKET_NAME, ListOptions.DEFAULT);
// ... and so on
关于java - Google App Engine - 未找到 GoogleCredential.getApplicationDefault(transport, jsonFactory),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38593324/