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
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
Share Improve this question edited Sep 18, 2013 at 13:23 Jost 1,53412 silver badges18 bronze badges asked Sep 18, 2013 at 12:56 fred-user2791470fred-user2791470 991 gold badge1 silver badge6 bronze badges 1- 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! – fred-user2791470 Commented Sep 24, 2013 at 22:28
2 Answers
Reset to default 2if 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()
.