2017-06-15 17 views
0

私はgoogle-cloud-platformから始めています。私は雲のコンソールのアカウントとプロジェクトを作成しました。私は提供されているサンプルアプリケーションのいくつかを実行しようとしていました。 私はで提供するクラウドストレージ用のサンプルアプリを開始しました:私は私のPC上のApache Mavenの3.5.0をインストールしているGoogleのクラウドプラットフォームのサンプルアプリケーションを実行できません

https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/storage/cloud-client

。 私はリンクで示す手順に従って、それは私には、以下のコマンドを与えている:

mvn clean package -DskipTests 

、その後

mvn exec:java -Dexec.mainClass=com.example.storage.QuickstartSample -Dexec.args="my-bucket-name" 

最初のコマンドは成功しました。ただし、2番目のコマンドは失敗しました。 は、私は次のエラーました:今

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 01:06 min 
[INFO] Finished at: 2017-06-15T18:27:55+05:30 
[INFO] Final Memory: 15M/172M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project storage-google-cloud-samples: An exception occured while executing the Java class. connect timed out -> [Help 1] 

を、私はこのコマンドを実行していたコンピュータは、プロキシの背後にあります。しかし、私のプロキシ設定はファイルconf/settings.xmlに設定されています。また、最初のコマンドを実行したときにいくつかのパッケージを正常にダウンロードしたので、チェックするためにプロキシの問題があるかどうかはわかりません。プロキシの背後にない別のマシンで試してみました。

私は同じ2つのコマンドを与えました。一つ目は成功し、第二には、以下の(別の)エラーで、再び失敗しました:

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 01:02 min 
[INFO] Finished at: 2017-06-15T18:22:31+05:30 
[INFO] Final Memory: 13M/32M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (d 
efault-cli) on project storage-google-cloud-samples: An exception occured while 
executing the Java class. 401 Unauthorized -> [Help 1] 

は、だから私のクエリは、次のとおりです。

  1. 最初のケースでエラーの原因である可能性がありますか?プロキシの設定と関係がありますか?はいの場合は、どのように設定する必要がありますか?

  2. 私がプロキシの背後にない2番目のケースでは、エラーの原因は何でしょうか?

  3. ここにいくつかのステップがありませんか?

  4. また、このサンプルアプリケーションのソースを見ると、基本的にバケットを作成するファイルが1つだけあります。バケットはコマンドラインから引数として渡されます。さて、私の理解によれば、まず、クラウドコンソールにプロジェクトを作成してリソースを作成する必要があります。では、このバケットはどこに作成されますか?このバケットを作成するプロジェクトIDを指定してはいけませんか?

+0

Googleグループはありますか? –

+0

リンクhttps://cloud.google。com/support/docs/community、 技術的な質問についてはスタックオーバーフローが推奨されます –

答えて

1

TL; DR - あなたは資格情報が欠落している、の例では、希望のGoogle Cloud APIを呼び出すために依存しています。クライアントライブラリのいずれかを使用してGoogle Cloud APIを使用する場合は、Application Default Credentialsを使用することをお勧めします。

をバージョン

長い例はApplication Default Credentials(あなたが使用しているGitHubのレポのas explained in the README.md)に依存しています。

How the Application Default Credentials work

You can get Application Default Credentials by making a single client library call. The credentials returned are determined by the environment the code is running in. Conditions are checked in the following order:

  1. The environment variable GOOGLE_APPLICATION_CREDENTIALS is checked. If this variable is specified it should point to a file that defines the credentials. The simplest way to get a credential for this purpose is to create a Service account key in the Google API Console:

    a. Go to the API Console Credentials page .

    b. From the project drop-down, select your project.

    c. On the Credentials page, select the Create credentials drop-down, then select Service account key.

    d.From the Service account drop-down, select an existing service account or create a new one.

    e. For Key type, select the JSON key option, then select Create. The file automatically downloads to your computer.

    f. Put the *.json file you just downloaded in a directory of your choosing. This directory must be private (you can't let anyone get access to this), but accessible to your web server code.

    g. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file downloaded.

  2. If you have installed the Google Cloud SDK on your machine and have run the command gcloud auth application-default login , your identity can be used as a proxy to test code calling APIs from that machine.

  3. If you are running in Google App Engine production, the built-in service account associated with the application will be used.

  4. If you are running in Google Compute Engine production, the built-in service account associated with the virtual machine instance will be used.

  5. If none of these conditions is true, an error will occur.

関連する問題