This page provides a short exercise in building a command-line TaskList application with the Firestore in Datastore mode API. The TaskList application stores, lists, updates, and removes tasks.
Prerequisites
- Ability to write and run a command line application in the programming languages used in this topic
In addition to a basic understanding of how to develop applications, you should be able to download and install additional libraries before attempting this tutorial. - A Google Cloud project with the Datastore mode API enabled
Applications that use Datastore mode are associated with a Google Cloud project with the Datastore mode API enabled. This project provides authentication credentials you use in your application to identify it to Google and authorize its use of the Datastore mode API.
Follow these instructions to create a project, enable the Datastore mode API for it, and set up your local development environment with authentication credentials using thegcloud auth logincommand. Make a note of the project's ID, which you'll use later on.
Installation and setup
Install client libraries and configure any additional settings for your development environment.
C#
- Ensure you have Visual Studio (version 2013 or later) installed.
- Download the TaskList sample application from the samples repository.
- Extract the files from the zip into a directory in your Documents folder.
- In Visual Studio, open the file
dotnet-docs-samples-master\datastore\api\Datastore.sln. - In Visual Studio's Solution Explorer window, right-click the TaskList project and choose Set as StartUp Project.
- Right-click the TaskList project again and choose Properties.
In the Properties window, click Debug and type the ID of your Google Cloud project into the Command line arguments: box.

Click File and then click Save to save your changes.
Run the application! Press F5 on your keyboard.
Go
Clone the TaskList sample application.
go get github.com/GoogleCloudPlatform/golang-samples/datastore/tasksChange directories to where you cloned the sample:
cd $GOPATH/src/github.com/GoogleCloudPlatform/golang-samples/datastore/tasksAt a command prompt, run the following, where
<project-id>is the ID of your Google Cloud project.export DATASTORE_PROJECT_ID=<project-id>(Windows users: use
setinstead ofexport.)Run the application!
go run tasks.go
Java
Ensure you have Maven and Java (version 8 or later) installed.
Download the TaskList sample application from the samples repository.
At a command prompt, extract the download:
unzip main.zipChange directories to the TaskList application:
cd java-datastore-main/samples/snippetsRun the following, where
<project-id>is the ID of your Google Cloud project.gcloud config set project <project-id>Compile and run the application!
mvn clean compile mvn exec:java -Dexec.mainClass="com.google.datastore.snippets.TaskList"
Node.js
Download the TaskList sample application from the samples repository.
Extract the download:
unzip master.zipChange directories to the TaskList application:
cd nodejs-datastore-master/samplesInstall the dependencies and link the application:
npm installAt a command prompt, run the following, where
<project-id>is the ID of your Google Cloud project.export GCLOUD_PROJECT=<project-id>(Windows users: use
setinstead ofexport.)Run the application!
node tasks.js
PHP
- Ensure you have PHP (version 5.6 or later) and Composer installed.
- Download the TaskList sample application from the samples repository.
Extract the download:
unzip master.zipChange directories to the TaskList application:
cd php-docs-samples-master/datastore/tutorialInstall dependencies.
composer installRun the application!
php src/list_tasks.php
Python
- Ensure you have Python (version 2.7.9 or later), pip, and virtualenv installed.
Activate a
virtualenvsession.virtualenv venv source venv/bin/activateDownload the TaskList sample application from the samples repository.
Extract the download:
unzip master.zipChange directories to the TaskList application:
cd python-docs-samples-master/datastore/cloud-clientInstall dependencies:
pip install -r requirements.txtRun the application! Use the ID of your Google Cloud project for
<project-id>.python tasks.py new project-id
Ruby
Download the TaskList sample application from the samples repository.
Extract the download:
unzip master.zipChange directories to the TaskList application:
cd google-cloud-ruby-master/google-cloud-datastore/samplesInstall the dependencies:
bundle installAt a command prompt, run the following, where
<project-id>is the ID of your Google Cloud project.export GOOGLE_CLOUD_PROJECT=<project-id>(Windows users: use
setinstead ofexport.)Run the application!
bundle exec ruby tasks.rb
Creating an Authorized Service Object
In order to make authenticated requests to Google Cloud APIs using the Google APIs Client libraries, you must:
- Fetch the credential to use for requests.
- Create a service object that uses that credential.
You can then make API calls by calling methods on the Datastore mode service object.
For this example, you'll fetch Application Default Credentials from the environment, and pass it as an argument to create the service object.
Here's the call to create the authorized Datastore mode service object:
C#
To learn how to install and use the client library for Cloud Datastore, see Cloud Datastore client libraries. For more information, see the Cloud Datastore C# API reference documentation.
To authenticate to Cloud Datastore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
To learn how to install and use the client library for Cloud Datastore, see Cloud Datastore client libraries. For more information, see the Cloud Datastore Go API reference documentation.
To authenticate to Cloud Datastore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To learn how to install and use the client library for Cloud Datastore, see Cloud Datastore client libraries. For more information, see the Cloud Datastore Java API reference documentation.
To authenticate to Cloud Datastore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To learn how to install and use the client library for Cloud Datastore, see Cloud Datastore client libraries. For more information, see the Cloud Datastore Node.js API reference documentation.
To authenticate to Cloud Datastore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PHP
To learn how to install and use the client library for Cloud Datastore, see Cloud Datastore client libraries. For more information, see the Cloud Datastore PHP API reference documentation.
To authenticate to Cloud Datastore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To learn how to install and use the client library for Cloud Datastore, see Cloud Datastore client libraries. For more information, see the Cloud Datastore Python API reference documentation.
To authenticate to Cloud Datastore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Ruby
To learn how to install and use the client library for Cloud Datastore, see Cloud Datastore client libraries. For more information, see the