I used the code sample in Quickstart and tried inserting an event using the example on - https://developers.google.com/calendar/v3/reference/events/insert#examples
I checked the resources available over the web and none of them seem to be working for me (downgrading googleapis package to version 24.0.0 or using different ways of writing the insert event). This is the code of the addEvents function currently -
function addEvents(auth){
var event = {
"summary": "Google I/O 2015",
"location": "800 Howard St., San Francisco, CA 94103",
"description": "A chance to hear more about Google's developer products.",
"start": {
"dateTime": "2015-05-28T09:00:00-07:00",
"timeZone": "America/Los_Angeles",
},
"end": {
"dateTime": "2015-05-28T17:00:00-07:00",
"timeZone": "America/Los_Angeles",
},
"recurrence": [
"RRULE:FREQ=DAILY;COUNT=2"
],
"reminders": {
"useDefault": false,
"overrides": [
{"method": "email", "minutes": 24 * 60},
{"method": "popup", "minutes": 10},
],
},
};
//console.log(event)
var calendar = google.calendar("v3");
calendar.events.insert({
auth: auth,
calendarId: "primary",
resource: event,
}, function(err, event) {
if (err) {
console.log("There was an error contacting the Calendar service: " + err);
return;
}
console.log("Event created: %s", event.htmlLink);
});
}
It is on the same lines as the listEvents function -
function listEvents(auth) {
var calendar = google.calendar('v3');
calendar.events.list({
auth: auth,
calendarId: 'primary',
timeMin: (new Date()).toISOString(),
maxResults: 10,
singleEvents: true,
orderBy: 'startTime'
},
function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
var events = response.items;
if (events.length == 0) {
console.log('No upcoming events found.');
}
else {
console.log('Upcoming 10 events:');
for (var i = 0; i < events.length; i++) {
var event = events[i];
var start = event.start.dateTime || event.start.date;
console.log('%s - %s', start, event.summary);
}
}
});
}
Can anyone please help me with this?
Thanks!
These are the things you need to do to get the issue resolved -
var {google} = require('googleapis');
instead of var google = require('googleapis');
Write var OAuth2 = google.auth.OAuth2;
instead of var googleAuth = require('google-auth-library');
Do not npm install google-auth-library
. If you did, remove it from your package.json and do npm install
again.
Make sure you have the latest version of googleapis
package. If you do not - do npm install googleapis@27
to get it. (Also add it to the package.json for future).
For any callback - instead of response.items
, do response.data.items
. You do not necessarily need the callback output when you create an event but you definitely need it when you list events. So do not forget to make this change there.
I don't think there would be any issue once you follow all these steps. If there still is, just reply to this. I will try my best to get it resolved!