Complete the steps described in the rest of this page to create a simple Node.js command-line application that makes requests to the Google Sheets API.
Prerequisites
To run this quickstart, you need the following prerequisites:
- Node.js & npm installed.
- A Google account
Step 1: Turn on the Google Sheets API
Click this button to create a new Cloud Platform project and automatically enable the Google Sheets API:
In resulting dialog click DOWNLOAD CLIENT CONFIGURATION and save the file
credentials.json
to your working directory.
Step 2: Install the client library
Run the following commands to install the libraries using npm:
npm install googleapis@27 --save
Step 3: Set up the sample
Create a file named index.js
in your working directory and copy in
the following code:
Step 4: Run the sample
Run the sample using the following command:
node .
The first time you run the sample, it will prompt you to authorize access:
Browse to the provided URL in your web browser.
If you are not already logged into your Google account, you will be prompted to log in. If you are logged into multiple Google accounts, you will be asked to select one account to use for the authorization.
- Click the Accept button.
- Copy the code you're given, paste it into the command-line prompt, and press Enter.
Notes
- Authorization information is stored on the file system, so subsequent executions will not prompt for authorization.
- The authorization flow in this example is designed for a command line application. For information on how to perform authorization in other contexts, see the Authorizing and Authenticating. section of the library's README.