You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-2Lines changed: 48 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,15 +45,61 @@ Example Applications
45
45
-[`StorageExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java) - A simple command line interface providing some of Cloud Storage's functionality
46
46
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/StorageExample.html).
47
47
48
+
Specifying a Project ID
49
+
-----------------------
50
+
51
+
Most `gcloud-java` libraries require a project ID. There are multiple ways to specify this project ID.
52
+
53
+
1. When using `gcloud-java` libraries from within Compute/App Engine, there's no need to specify a project ID. It is automatically inferred from the production environment.
54
+
2. When using `gcloud-java` elsewhere, you can do one of the following:
55
+
* Supply the project ID when building the service options. For example, to use Datastore from a project with ID "PROJECT_ID", you can write:
* Specify the environment variable `GCLOUD_PROJECT` to be your desired project ID.
61
+
* Set the project ID using the [Google Cloud SDK](https://cloud.google.com/sdk/?hl=en). To use the SDK, [download the SDK](https://cloud.google.com/sdk/?hl=en) if you haven't already, and set the project ID from the command line. For example:
62
+
63
+
```
64
+
gcloud config set project PROJECT_ID
65
+
```
66
+
67
+
`gcloud-java` determines the project ID from the following sources in the listed order, stopping once it finds a value:
68
+
69
+
1. Project ID supplied when building the service options
70
+
2. Project ID specified by the environment variable `GCLOUD_PROJECT`
71
+
3. App Engine project ID
72
+
4. Compute Engine project ID
73
+
5. Google Cloud SDK project ID
74
+
48
75
Authentication
49
76
--------------
50
77
51
78
There are multiple ways to authenticate to use Google Cloud services.
52
79
53
80
1. When using `gcloud-java` libraries from within Compute/App Engine, no additional authentication steps are necessary.
54
81
2. When using `gcloud-java` libraries elsewhere, there are two options:
55
-
*[Generate a JSON service account key](https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts). Supply a path to the downloaded JSON credentials file when building the options supplied to datastore/storage constructor.
56
-
* If running locally for development/testing, you can use use [Google Cloud SDK](https://cloud.google.com/sdk/?hl=en). To use the SDK authentication, [download the SDK](https://cloud.google.com/sdk/?hl=en) if you haven't already. Then login using the SDK (`gcloud auth login` in command line), and set your current project using `gcloud config set project PROJECT_ID`.
82
+
*[Generate a JSON service account key](https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts). After downloading that key, you must do one of the following:
83
+
* Define the environment variable GOOGLE_APPLICATION_CREDENTIALS to be the location of the key. For example:
* Supply the JSON credentials file when building the service options. For example, this Storage object has the necessary permissions to interact with your Google Cloud Storage data:
* If running locally fordevelopment/testing, you can use use Google Cloud SDK. Download the SDK if you haven't already, then login using the SDK (`gcloud auth login`incommand line). Be sure to set your project ID as described above.
95
+
96
+
`gcloud-java` looks forcredentialsin the following order, stopping once it finds credentials:
97
+
98
+
1. Credentials supplied when building the service options
99
+
2. App Engine credentials
100
+
3. Key file pointed to by the GOOGLE_APPLICATION_CREDENTIALS environment variable
0 commit comments