简体   繁体   中英

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

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().

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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM