我写一个Java应用程序与在谷歌云存储文件交互。我发现gcloud-java
,我正在努力工作。如何验证自己与谷歌云存储的Java应用程序?
看着他们的examples看来我应该能够在用gcloud
登录后简单地运行它们,但它似乎并没有工作。我试图运行StorageExample
,它说,但尽管登录我无法访问我的项目,我是否指定与否“如果没有提供登录项目将使用”。
$ gcloud auth login
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?....
Saved Application Default Credentials.
You are now logged in as [...].
Your current project is [...]. You can change this setting by running:
$ gcloud config set project PROJECT_ID
$ java -cp GCloudDemo.jar com.google.gcloud.examples.storage.StorageExample list
Exception in thread "main" java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment. Please set a project ID using the builder.
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:122)
at com.google.gcloud.ServiceOptions.<init>(ServiceOptions.java:317)
...
at com.google.gcloud.examples.storage.StorageExample.main(StorageExample.java:566)
$ java -cp GCloudDemo.jar com.google.gcloud.examples.storage.StorageExample ... list
Exception in thread "main" com.google.gcloud.storage.StorageException: Login Required
at com.google.gcloud.spi.DefaultStorageRpc.translate(DefaultStorageRpc.java:94)
at com.google.gcloud.spi.DefaultStorageRpc.list(DefaultStorageRpc.java:148)
...
at com.google.gcloud.examples.storage.StorageExample$ListAction.run(StorageExample.java:1)
at com.google.gcloud.examples.storage.StorageExample.main(StorageExample.java:579)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
"code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "Login Required",
"reason" : "required"
} ],
"message" : "Login Required"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
...
at com.google.gcloud.spi.DefaultStorageRpc.list(DefaultStorageRpc.java:138)
... 10 more
显然东西是错误与我的环境,但我有什么做的,解决这个问题?我想改正我的环境,而不是对示例进行更改。
注:
- 我在Windows 10上运行Cygwin中2.0.4
- 我不是通过Maven的建设,但我假设这不是问题 源
作为一个更新,我就可以更容易地把事情用[WSL]工作(https://msdn.microsoft.com/en-us/commandline/wsl)比Cygwin的:) – dimo414