简体   繁体   English

谷歌日历api v3 calendar.events.list并在javascript中使用timeMax,timeMin

[英]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 !!!!! 这个javascript正在返回日历中的所有事件!!!!!

plugging those time values into v3 api explorer and the correct time range of events return. 将这些时间值插入v3 api explorer并返回正确的事件时间范围。

so how the freak to get my javascript to do the same ? 那么怪物怎么让我的javascript做同样的事情? i tried heaps of permutations, whys it so freaking hard this google api stuff....... 我尝试了大量的排列,为什么它如此疯狂这个谷歌api的东西.......

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. 显然我看到了一个使用insert()api工作的例子。 But that is the Events resource as documented for insert(). 但这是为insert()记录的Events资源。

When using Google Script, with API v2 and v3, you can write: 使用Google Script时,使用API​​ v2和v3,您可以编写:

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. Calendar.Events.list调用中的技巧是第一个参数是日历id,第二个参数是对象。 When passing dates, need to use x.toISOString() . 传递日期时,需要使用x.toISOString()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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