question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calendar API V3 doesn't respect timeMin timeMax parameters in nodejs Express application

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
samovercommented, Feb 1, 2018

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

1reaction
Lovinitycommented, May 14, 2018

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 });

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Calendar API V3 doesn't respect timeMin timeMax ...
But when i use same cording with nodeJs Express App, It doesn't respect the timeMin and timeMax parameters. Instead, i get all the...
Read more >
Google Calendar API V3 doesn't respect timeMin timeMax ...
Coding example for the question Google Calendar API V3 doesn't respect timeMin timeMax parameters in nodejs Express application-node.js.
Read more >
How to integrate Google Calendar in Node.js ? - GeeksforGeeks
This article covers the integration of Google Calendar API in the NodeJS application and creating new events with service account ...
Read more >
ExpressJS with the Google Calendar API - Kaz Yamada
Install ExpressJS and dotenv save it in the dependencies list. CLI. npm install express dotenv. Create an entry file index.js ...
Read more >
Calendar - googleapis documentation
File. src/apis/calendar/v3.ts. Description. Calendar API. Manipulates events and other calendar data. const {google} = require('googleapis'); const calendar ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found