Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google calendar api v3 calendar.events.list and using timeMax,timeMin in javascript

var resource = {
    ///  "kind": "calendar#event",

    "alwaysIncludeEmail" : "true",
    "singleEvents" : "true",
    "orderBy" : "startTime",
    "timeMax": {
        "dateTime": "2013-10-01T00:00:00+10:00" //maxDate.toISOString()
    },
    "timeMin": {
        "dateTime":  "2013-08-29T00:00:00+10:00" //startDateMin.toISOString()
    }
};

var calendar_id = new calendarIds();

var request = gapi.client.calendar.events.list({
    'calendarId': calendar_id.source,
    'resource': resource
});

....

request.execute(function(resp){

this javascript is returning ALL events in the calendar !!!!!

plugging those time values into v3 api explorer and the correct time range of events return.

so how the freak to get my javascript to do the same ? i tried heaps of permutations, whys it so freaking hard this google api stuff.......

need a working example please

like image 814
fred-user2791470 Avatar asked Sep 18 '13 12:09

fred-user2791470


2 Answers

if the request is rewritten as

 var request = gapi.client.calendar.events.list({
      'calendarId': calendar_id,
      "singleEvents" : true,
      "orderBy" : "startTime",
      "timeMin":  startDate.toISOString(),
      "timeMax":  maxDate.toISOString()
    });

  request.execute(function(resp){

it now works!

there is some confusion with that "resource" parameter. Obviously i saw an example that worked using the insert() api. But that is the Events resource as documented for insert().

like image 64
fred-user2791470 Avatar answered Oct 14 '22 01:10

fred-user2791470


When using Google Script, with API v2 and v3, you can write:

var calendar_id = CalendarApp.getCalendarById('My Test Calendar')[0];
var start_date = new Date();
var query = Calendar.Events.list(calendar_id, {timeMin: start_date.toISOString()});
var events = query.items;

Tricks in the Calendar.Events.list call is that the first parameter is the calendar id, the second is an object. When passing dates, need to use x.toISOString().

like image 21
Glen Little Avatar answered Oct 14 '22 00:10

Glen Little