# google-cloud

Google Cloud Client Library for Java - an idiomatic, intuitive, and natural way for Java developers to integrate with Google Cloud Platform services, like Cloud Datastore and Cloud Storage.

- Read the Docs
- Github
- Issues
- StackOverflow
- Package Information

### What is it?

`google-cloud` is a client library for accessing Google Cloud Platform services that significantly reduces the boilerplate code you have to write. The library provides high-level API abstractions so they're easier to understand. It embraces idioms of Java, works well with the standard library, and integrates better with your codebase. All this means you spend more time creating code that matters to you.

`google-cloud` is configured to access Google Cloud Platform services and authorize (OAuth 2.0) automatically on your behalf. Add the `google-cloud` dependency to your project and get a private key to be up and ready to go. Better yet, if you are running on Google App Engine or Compute Engine, the private key is automatically detected.

#### Example: Retrieve Datastore Entries

Run in Compute/App Engine Run elsewhere

    import com.google.cloud.datastore.Datastore;
    import com.google.cloud.datastore.DatastoreOptions;
    import com.google.cloud.datastore.Entity;
    import com.google.cloud.datastore.Key;
    import com.google.cloud.datastore.KeyFactory;

    // Authentication is automatic inside Google Compute Engine
    // and Google App Engine.
    Datastore datastore =
      DatastoreOptions.getDefaultInstance().getService();
    KeyFactory keyFactory = datastore.newKeyFactory().setKind(KIND);
    Key key = keyFactory.newKey(keyName);
    Entity entity = datastore.get(key);

    import com.google.auth.oauth2.GoogleCredentials;
    import com.google.cloud.datastore.Datastore;
    import com.google.cloud.datastore.DatastoreOptions;
    import com.google.cloud.datastore.Entity;
    import com.google.cloud.datastore.Key;
    import com.google.cloud.datastore.KeyFactory;

    DatastoreOptions options = DatastoreOptions.newBuilder()
      .setProjectId(PROJECT_ID)
      .setCredentials(GoogleCredentials.fromStream(
        new FileInputStream(PATH_TO_JSON_KEY))).build();
    Datastore datastore = options.getService();
    KeyFactory keyFactory = datastore.newKeyFactory().setKind(KIND);
    Key key = keyFactory.newKey(keyName);
    Entity entity = datastore.get(key);

### Examples

- `Bookshelf` - An App Engine app that manages a virtual bookshelf using google-cloud libraries for Datastore and Storage.
- `Flexible Environment/Datastore example` - A simple app that uses Cloud Datastore to list the last 10 IP addresses that visited your site. Read about how to run the application here.
- `Flexible Environment/Storage example` - An app that uploads files to a public Cloud Storage bucket on the App Engine Flexible Environment runtime.
- `GuestBook` - An App Engine Standard guestbook that uses Cloud Datastore.
- `SparkJava demo` - Uses google-cloud with App Engine Flexible Environment, Datastore, and SparkJava.
- `TaskList` - A command line app that manages a to-do list using Cloud Datastore.

### FAQ

#### What is the relationship between the `google-cloud` library and the `gcloud` command-line tool?

Both the `gcloud` command-line tool and `google-cloud` library are a part of the Google Cloud SDK: a collection of tools and libraries that enable you to easily create and manage resources on the Google Cloud Platform. The `gcloud` command-line tool can be used to manage both your development workflow and your Google Cloud Platform resources while the `google-cloud` library is the Google Cloud Client Library for Java.

#### What is the relationship between `google-cloud` and the Google APIs Java Client?

The Google APIs Java Client is a client library for using the broad set of Google APIs. `google-cloud` is built specifically for the Google Cloud Platform and is the recommended way to integrate Google Cloud APIs into your Java applications. If your application requires both Google Cloud Platform and other Google APIs, the 2 libraries may be used by your application.

#### Does it work on Android?

Android is currently unsupported.