0.2.1 • Published 5 years ago
@muffin-dev/google-helpers v0.2.1
Muffin Dev for Node - Google Helpers
This module contains a bunch of tools and utilities to make the use of Google APIs easier.
Supported APIs
How to use?
const path = require('path');
const GoogleAPIManager = require('..').default;
async function testReadData() {
const manager = await GoogleAPIManager.create(
path.join(__dirname, './credentials.json'),
path.join(__dirname, './token.json'),
'installed'
);
// This example reads a Google Sheet
const data = await manager.spreadsheets.read('your-gsheet-id', 'Data!A1:C100');
console.log('Loaded data', data);
}
testReadData();Get credentials
Using the Google APIs requires to use credentials, which can be provided from your Google Cloud Project by downloading the credentials.json file. You can also get that file by enabling the Google Sheets API from the quickstart docs.
Generate a token.json file
You can use the generateToken command of this package to generate a new token.json file. First, update your package.json:
"scripts": {
"generateToken": "generateToken"
}Then, run the command:
npm run generateToken -- <credentials-path> <credentials-type> <token-path> <... scopes><credentials-path>: Path to yourcredentials.jsonfile<credentials-type>: The credentials type to use from yourcredentials.jsonfile (for exampleweb,installed, ...) depending on your app's target device<token-path>: Path to yourtoken.jsonfile<... scopes>: The target scopes of the token to generate (e.g.: https://www.googleapis.com/auth/spreadsheets.readonly). You can add as many scopes as you want, separated by spaces