初学者谷歌应用程序制造商日历样本

时间:2018-03-22 22:55:14

标签: google-calendar-api google-app-maker

我真的是Appmaker的初学者。 如何从特定日历而不是默认日历中获取事件?

我尝试了几件事,但我需要一些帮助。

我尝试调用CalendarApp.getCalendarsByName("");而不是CalendarApp.getDefaultCalendar()

但我被困了

任何提示?

 /**
 * Gets Calendar events.
 * @param {Query} query - data query with parameters.
 * @return {Array<Event>} events from Calendar.
 */
function getEvents_(query) {
  var startDate = query.parameters.StartDate;
  startDate.setHours(0, 0, 0, 0);

  var endDate = query.parameters.EndDate;
  endDate.setDate(endDate.getDate() + 1);
  endDate.setHours(0, 0, 0, 0);

  if (startDate.getTime() > endDate.getTime()) {
    return [];
  }

  var results = [];
  var events = CalendarApp.getDefaultCalendar().getEvents(startDate,endDate);




  events.forEach(function(item) {
var event = app.models.Events.newRecord();
event.StartDate = item.getStartTime();
event.EndDate = item.getEndTime();
event.Title = item.getTitle();
event.Color = item.getColor();
results.push(event);
  });

return results;
}

2 个答案:

答案 0 :(得分:0)

I think you need to use Advanced Calendar API for it. You can plug it in in App Maker settings: Advanced Service

Once you turn it on try this script:

var events = Calendar.Events.list(calendarId, {
  timeMin: startDate.toISOString(),
  timeMax: endDate.toISOStrng(),
  singleEvents: true,
  orderBy: 'startTime',
  maxResults: 10
});

You can find more info about list method parameters in this docs: https://developers.google.com/calendar/v3/reference/events/list

答案 1 :(得分:0)

感谢提示!

未添加Calendar API服务。

现在工作得非常好:

var id = 'mycalendarID@group.calendar.google.com';
CalendarApp.getCalendarById(id).getEvents(startDate, endDate);