Skip to content

Repository files navigation

@anmiles/google-api-wrapper

Wrapper around googleapis for getting data shortly

  • provides quick interface for getting google API data
  • encapsulates auth process
  • combines getting paged items in one call

Installation

npm install @anmiles/google-api-wrapper

Usage

Authorization

/* auth.js */import{createProfile,login}from'@anmiles/google-api-wrapper';createProfile("username");// Persistent credentials will be generated and stored to credentials file.// Next `login` call will re-use persistent credentials without showing oauth windowlogin("username");

Example with persisted auth

/* calendar.js */import{calendar}from'googleapis/build/src/apis/calendar';import{getProfiles,getAPI}from'@anmiles/google-api-wrapper';require('./auth');getProfiles().map(async(profile)=>{// Persistent credentials will be generated and stored to credentials file.// Next `getAPI` call will re-use persistent credentials without showing oauth windowconstcalendarAPI=getAPI((auth)=>calendar({version : 'v3', auth }),profile);constevents=awaitcalendarAPI.getItems((api)=>api.events,{timeMax: newDate().toISOString()});events.forEach((event)=>console.log(`Event: ${event.summary}`));});

Example with temporary auth

/* videos.js */import{youtube}from'googleapis/build/src/apis/youtube';import{getProfiles,getAPI}from'@anmiles/google-api-wrapper';getProfiles().map(async(profile)=>{// Temporary credentials will be generated and not stored to credentials file// Next `getAPI` will start authorization again with showing oauth windowconstyoutubeAPI=getAPI((auth)=>youtube({version : 'v3', auth }),profile,{temporary: true});constvideos=awaityoutubeAPI.getItems((api)=>api.playlistItems,{playlistId : 'LL',part : ['snippet'],maxResults : 50});videos.forEach((video)=>console.log(`Downloaded: ${video.snippet?.title}`));});

Live examples

About

Wrapper around googleapis for getting data shortly

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages