我寫一個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