Java console application showing how to interact with Google Drive.This is a simple command line client application that eliminates unnecessary clutter and shows the basic logic to interact with Google Drive. Hopefully this will help you to understand the syntax (and semantic) of the API. The following figure is the application architecture (class diagram):
The application interacts with the Google Drive via its REST API using the related Google Java client library. For more information, see Google API Client Libraries. See also Cloud Programming REST API. See related blog post at Build GCP Drive Client.
You must have Maven installed. The dependencies are satisfied by building the Maven package. The application uses a custom client authentication app. The app is included as a JAR in the downloadable code. Please include this JAR in your project. For more information, see GCP Cloud Service Client Apps – Common Tasks. See also Build GCP Service Authentication.
You need to set up your Google security credentials before the sample code is able to connect to the Google Storage service. You can do this by creating a file named "client_secrets.json" at ~/.store/storage_sample (C:\Users\USER_NAME.store\storage_sample\ for Windows users) and saving the following information in the file:
- Client ID
- Client secrets
You obtain this information by downloading the JSON format of the client information for native application of your project at: Google Console. Then copy this information in the secretsFile such as client_secrets.json. Keep this file in a safe place.
The application assumes that a file exists that contains default settings. The file is assumed to be at ~/.store/storage_sample/sample_settings.json (C:\Users\USER_NAME.store\storage_sample\sample_settings.json for Windows users). The settigs are in Jason format similar to the following:
"project": "<your project ID>", "defaultbucket": "<name of your default bucket>", "defaultobject": "<name of your default object>", "prefix": "<your prefix>", "email":<your e-mail>"
The application connects to Running the ExampleGoogle Cloud Storage, and allows the user to create a bucket, upload an object into the bucket, download the object, delete the object and delete the bucket. All you need to do is run it by following these steps:
From the project, create an executable JAR
From a terminal window, go to the directory containing the JAR and execute a command similar to the following:
java -jar gcp-drive-client.jar
This sample application is distributed under the