最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin6浏览0评论
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
Add a ment  | 

2 Answers 2

Reset to default 2

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

发布评论

评论列表(0)

  1. 暂无评论