首页 文章

通过Google Apps脚本向非Google帐户发送日历邀请

提问于
浏览
2

我创建了一个Google表单,可以在提交时将信息输入Google表格 .

我创建了一段在提交时运行的Google Apps脚本代码,用于创建日历活动,并使用高级日历API在我在“表单”所有者的Google帐户中创建的非主要Google日历上创建活动 .

作为事件对象的一部分,我正在设置一个收件人电子邮件地址的 attendees 属性数组,以接收对该事件的邀请 . 我也将 sendNotifications 设置为true .

通过API创建事件时,我可以看到事件是在我指定的日历中创建的 . 与会者列表中填充了我指定的收件人电子邮件地址 .

拥有Google帐户的收件人会将日历活动作为暂定约会直接添加到其日历中 . 非Google收件人(例如Hotmail用户,Exchange用户,Office 365等)只需 do not 即可收到邀请 .

此外,通过日历UI编辑创建的事件会提示我“更新访客”的更改 . 确认这一点会导致非Google收件人成功收到有关事件更改的电子邮件通知 . 此外,直接通过日历UI创建活动并指定非Google与会者也会导致邀请成功传递 .

只是通过Calendar API创建事件似乎不起作用 .

更复杂的是,如果我访问Google events reference page,并使用 Try it! 表单(使用OAuth连接到API),那么我可以将数据发布到API并成功接收来自非Google地址的活动邀请 .

我想我可以连接某种Google API服务帐户,编写一些Google Apps脚本代码,通过OAuth插件通过该服务帐户进行授权,然后尝试通过某种外部API请求调用API到Google日历API - 但是我必须弄清楚如何从Google Apps脚本中获取OAuth的功能 . 即便如此,当Google Apps脚本支持无论如何在内部使用Calendar API时,似乎有点过分了 .

只是添加:我已经授权脚本通过脚本编辑器的高级Google服务区域以及开发人员控制台使用Calendar API,如this article中所建议的那样 .

我还发现this article暗示 patching 是一个支持发送邀请的事件 - 结果是相同的,但仍然不适用于非Google帐户 .

我的代码如下:

// set variables
  var appointmentWith = "Nick W";
  var location = "The Boardroom";
  var description = "Add some notes to the appointment";
  var calendar = "1v1.....u80@group.calendar.google.com"; // calendar id of calendar
  /*
  joinedStart and endDate are set elsewhere
  */

  // create an event object
  var event = {
    summary: appointmentWith, // the title of the appointment
    location: location, // the location of the appointment
    description: description, // the form description / submitted values
    start: {
      dateTime: joinedStart.toISOString() // start time of the appointment
    },
    end: {
      dateTime: endDate.toISOString() // end time of the appointment
    },
    sendNotifications: true, // email the invite
    attendees: [
      {email: recipient}, // set the recipient email address
      {email: "user@googleaccount.com"},
      {email: "non-google-user@hotmail.com"}
    ]
  };



  Logger.log("creating new calendar event");
  event = Calendar.Events.insert(event, calendar); // creates the event but won't notify non-Google email accounts
  Logger.log(event.id);
  Logger.log("new calendar event created");

  // attempting to patch the event in the hope this will fix the issue
  Logger.log("sending further invites");
  event.attendees.push({email:"user@hotmail.com"});
  event = Calendar.Events.patch(event, calendar, event.id, { sendNotifications:true});

  Logger.log("sent");

1 回答

  • 0

    这个:

    sendNotifications:true,//通过电子邮件发送邀请

    应该设置为请求参数,而不是作为Event主体的一部分 .

    Calendar.Events.insert(事件,日历,{sendNotifications:true})

相关问题