google-sheet-apis
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

npm npm npm bundle size

NPM

google-sheet-apis

How to use it

1. Install the package

npm

npm install google-sheet-apis

yarn

yarn add google-sheet-apis

2. Set up to access Google Sheet API

2.1 Create a new project in Google Console

Go to Google Console >> Select a project >> NEW PROJECT >> Type your project's name >> CREATE

Show steps

2.2 Enable Google Sheets API

Select your project >> Search: Google Sheet API >> ENABLE

Show steps

2.3 Create Service Accounts Credentials

Credentials >> + CREATE CREDENTIALS >> Service account >> Type your service'name >> CREATE AND CONTINUE >> CONTINUE >> DONE

Show steps

2.4 Add JSON keys

Click on the email in Service Accounts >> KEYS >> ADD KEY >> Create new key >> JSON >> CREATE >> The key will be downloaded in your machine

Show steps

3. Prepare a Google Sheet

Copy the email in Service Accounts >> Create a new Google Sheet >> Type your sheet name >> Share with the copied email >> Editor >> Done

Then, add some dummy data to test

Show steps

4. Example to use the package

Example

const PRIVATE_KEY = 'your_private_key_in_the_json_file';
const CLIENT_EMAIL = 'your_client_email_in_the_json_file';

const { GoogleSheetApis } = require('google-sheet-apis');
const googleSheetApis = new GoogleSheetApis({
      private_key: PRIVATE_KEY,
      client_email: CLIENT_EMAIL,
});

const SPREADSHEET_ID = 'get_spreadsheet_id_in_the_sheet_URL';
// example https://docs.google.com/spreadsheets/d/1gJitO5lxYo499VYf_SyTob2Cg_iLsMwQVLDnPjBDbao/edit#gid=0
// spreadsheet id: 1gJitO5lxYo499VYf_SyTob2Cg_iLsMwQVLDnPjBDbao
const TAB_NAME = 'your_tab_name';
const START_COLUMN = 'A';
const END_COLUMN = 'F';

const getData = async () => {
      const data = await googleSheetApis.getData({
            spreadsheetId: SPREADSHEET_ID,
            tabName: TAB_NAME,
            startColumn: START_COLUMN,
            endColumn: END_COLUMN,
      });
      console.log(data);
};

getData();

Package Sidebar

Install

npm i google-sheet-apis

Weekly Downloads

3

Version

0.0.3

License

MIT

Unpacked Size

9.41 kB

Total Files

7

Last publish

Collaborators

  • haicao2805