【问题标题】:Get the last meeting date from Google Calendar using guest email address使用访客电子邮件地址从 Google 日历获取上次会议日期
【发布时间】:2020-11-18 19:51:38
【问题描述】:

我需要一种方法,可以在 Google 日历中扫描以前的会议(这可以追溯到几个月前),并找到与某人(电子邮件地址)的最后一次会议(Google 日历活动)以及我参加过的会议次数和他们在一起。

在文档中搜索:https://developers.google.com/apps-script/reference/calendar

没有通过电子邮件查找事件的方法。我需要返回的结果是上次会议的日期和包括该人在内的会议总数。

有人做过类似的事情吗?非常感谢您的帮助!

【问题讨论】:

  • 在您的问题中,meetings 是日历中的事件吗?
  • @Tanaike 正确。对不起,我应该指定的。将编辑它。
  • 感谢您的回复。在您的问题中,您想要使用客人的电子邮件检索日历中的所有事件,并且您想要检索最新事件和事件数量。我的理解正确吗?如果我的理解是正确的,我能问你关于你想检索的最新事件吗?在这种情况下,是事件 ID 还是其他值?

标签: javascript google-apps-script google-sheets gmail google-calendar-api


【解决方案1】:

您可以使用getEvents() 指定搜索查询,然后使用getGuestByEmail()getGuestStatus() 检查您是否遇到过他们。

function getLastEventWith(contactEmail) {
  const events = CalendarApp.getDefaultCalendar() // Doesn't have to be the default calendar
    .getEvents(new Date(1970, 0, 1), new Date(), { search: contactEmail })
    .reverse(); // Events are sorted earliest-to-latest, so reverse
  
  let total = 0;
  let lastEvent;
  for (let event of events) {
    const guest = event.getGuestByEmail(contactEmail);
    if (guest.getGuestStatus() === CalendarApp.GuestStatus.YES || guest.getGuestStatus() === CalendarApp.GuestStatus.OWNER) {
      if (total === 0) {
        lastEvent = event;
      }
      total++;
    }
  }
  return { lastEvent: lastEvent, total: total };
}


function test_getLastEventWith() {
  const { lastEvent, total } = getLastEventWith("someone@example.com");
  console.log(lastEvent.getTitle());
  console.log(lastEvent.getStartTime());
  console.log(total);
}

您可以通过使用Calendar Advanced Service 来减少调用次数。

【讨论】:

    猜你喜欢
    • 2020-08-07
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 2017-05-07
    • 1970-01-01
    相关资源
    最近更新 更多