I've managed to get all events between two dates as mentioned in quickstart example on pure nodeJs environment.
But when i use same cording with nodeJs Express App, It doesn't respect the timeMin and timeMax parameters.
Instead, i get all the events from the date that i created first event on calendar. Here is my code block looks like.
function listEvents(auth) {
var calendar = google.calendar('v3');
calendar.events.list({
auth: auth,
calendarId: 'primary',
timeMin: (new Date(Date.parse("2018-01-22"))).toISOString(),
timeMax: (new Date(Date.parse("2018-02-27"))).toISOString(),
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 {
// Do Some Stuff ...............
}
});
}
What am i missing here..?
Thanks!
The starter example seems to be incorrect, but in line with the documentation.
V0.x of the google-auth-library uses the request library, so passing a querystring options does the trick:
calendar.events.list(
{
auth: auth,
calendarId: 'primary',
},
{
qs: {
timeMin: (new Date(Date.parse("2018-01-22"))).toISOString(),
timeMax: (new Date(Date.parse("2018-02-27"))).toISOString(),
singleEvents: true,
orderBy: 'startTime'
}
}, function(err, response) {
...
The solution proposed in 946, however, is the more correct one, since it uses v1 of the google-auth-library which has changed the dependency on request for axios
Passing querystring options along with the request worked for me as @samover suggested.
+1
The solution above no longer works. Now qs must be 'params' due to a library change in the api, but calendar is ignoring those params again. Any suggestions?
Can you share the code snippet you're trying?
NVM I remedied this issue by switching to async await calls instead of using sync. It looks like in v30 at least, qs and params are not used; params are passed directly into the function as an object argument.
var events = await calendar.events.list({
calendarId: 'secret',
timeMin: currentdate.toISOString(),
timeMax: nextWeekDate.toISOString(),
singleEvents: true
});
Most helpful comment
The starter example seems to be incorrect, but in line with the documentation.
V0.x of the
google-auth-libraryuses the request library, so passing a querystring options does the trick:The solution proposed in 946, however, is the more correct one, since it uses v1 of the
google-auth-librarywhich has changed the dependency onrequestfor axios