I believe you want to add and remove events in a calendar using Node.js.
About quickstart.js for using calendar API, in order to use calendar API, at first, users have to retrieve client_secret.json with client ID, client secret and so on, and enable calendar API at API console.
As a next step, access token and refresh token have to be retrieved from Google using client_secret.json. Most of quickstart.js in Quickstart is used to retrieve them. var TOKEN_PATH = TOKEN_DIR + 'calendar-nodejs-quickstart.json'; includes the access token and refresh token retrieved using client_secret.json. The access token which has the expiration time can be retrieved from the refresh token which doesn't have the expiration time. At quickstart.js, access token is retrieved every running the script using the refresh token.
Functions except for listEvents(auth) in the quickstart.js are used for the authorization. At listEvents(auth), calendar API can be used by using the access token retrieved by the authorization.
Sample script
Following sample script is for adding and removing events. This supposes that Step 1 and Step 2 in Quickstart have already finished and quickstart.js is used.
For Node.js Quickstart sample, it modified listEvents(). When you use this sample script, please copy and paste Node.js Quickstart sample and change listEvents() as follows, and add following addEvents() and removeEvents().
function listEvents(auth) {
var calendar = google.calendar('v3');
addEvents(auth, calendar); // Add events
removeEvents(auth, calendar); // Remove events
}
1. Add events
Detail information is https://developers.google.com/google-apps/calendar/v3/reference/events/insert.
function addEvents(auth, calendar){
calendar.events.insert({
auth: auth,
calendarId: 'primary',
resource: {
'summary': 'Sample Event',
'description': 'Sample description',
'start': {
'dateTime': '2017-01-01T00:00:00',
'timeZone': 'GMT',
},
'end': {
'dateTime': '2017-01-01T01:00:00',
'timeZone': 'GMT',
},
},
}, function(err, res) {
if (err) {
console.log('Error: ' + err);
return;
}
console.log(res);
});
}
2. Remove events
Detail information is https://developers.google.com/google-apps/calendar/v3/reference/events/delete.
function removeEvents(auth, calendar){
calendar.events.delete({
auth: auth,
calendarId: 'primary',
eventId: "#####",
}, function(err) {
if (err) {
console.log('Error: ' + err);
return;
}
console.log("Removed");
});
}