Skip to content

Instantly share code, notes, and snippets.

@jason-dark
Last active January 27, 2019 01:41
Show Gist options
  • Save jason-dark/fd265ad1f9c71902818d37b7bbbe1bee to your computer and use it in GitHub Desktop.
Save jason-dark/fd265ad1f9c71902818d37b7bbbe1bee to your computer and use it in GitHub Desktop.
const { google } = require('googleapis');
const cal = google.calendar({
version: 'v3',
auth: 'XXXXXX-YOUR-API-KEY-HERE-XXXXXX'
});
// Set the calendar to query
const calendar = 'someone@domain.com';
// Set beginning of query to 3 pm tomorrow
const tomorrow3pm = new Date();
tomorrow.setDate(day.getDate() + 1);
tomorrow.setHours(15, 0, 0);
// Set end of query to 4 pm tomorrow
const tomorrow4pm = new Date();
tomorrow.setDate(day.getDate() + 1);
tomorrow.setHours(16, 0, 0);
// Make the query
cal.freebusy.query({
resource: {
// Set times to ISO strings as such
timeMin: new Date(tomorrow3pm).toISOString(),
timeMax: new Date(tomorrow4pm).toISOString(),
timeZone: 'NZ',
items: [{ id: calendar }]
}
}).then((result) => {
const busy = result.data.calendars[calendar].busy;
const errors = result.data.calendars[calendar].errors;
if (undefined !== errors) {
console.error('Check this this calendar has public free busy visibility');
} else if (busy.length !== 0) {
console.log('Busy');
} else {
console.log('Free');
}
}).catch((e) => {
console.error(e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment