通过 Google Apps 脚本向非 Google 帐户发送日历邀请
Sending calendar invites to non-Google accounts via Google Apps Script
我创建了一个 Google 表单,在提交时将信息输入 Google Sheet。
我创建了一段 Google Apps 脚本代码,该代码在提交时运行,创建日历事件并使用高级日历 API 在非主要 Google 我在表单所有者的 Google 帐户中创建的日历。
作为活动对象的一部分,我设置了一个 attendees
属性 收件人电子邮件地址数组,用于接收活动邀请。
我还将 sendNotifications
设置为 true。
当通过 API 创建事件时,我可以看到事件是在我指定的日历中创建的。
与会者列表中填充了我指定的收件人电子邮件地址。
拥有 Google 帐户的收件人会将日历事件作为暂定约会直接添加到他们的日历中。
非Google 收件人(例如 Hotmail 用户、Exchange 用户、Office 365 等)不会 收到邀请。
此外,通过日历 UI 编辑创建的事件会提示我进行 "update guests" 更改。确认这会使非 Google 收件人成功收到事件更改的电子邮件通知。
此外,直接通过日历 UI 创建活动并指定非 Google 与会者也会导致邀请成功发送。
只是通过日历创建事件API 似乎不起作用。
更复杂的是,如果我访问 Google events reference page,并使用 Try it! 表单(使用 OAuth 连接到 API)然后我可以 post 数据到 API 并成功收到来自非 Google 地址的活动邀请。
我想我 可以 连接某种 Google API 服务帐户,写一些 Google Apps 脚本代码来授权该服务帐户通过 OAuth 插件,并尝试通过某种外部 API 请求调用 API 到 Google 日历 API - 但我不确定如果这可行,我将不得不弄清楚如何从 Google Apps 脚本中获取 OAuth 内容。尽管如此,当 Google Apps 脚本支持在内部使用日历 API 时,似乎有点过分。
补充一下:我已经授权脚本通过脚本编辑器的高级 Google 服务区域以及开发人员控制台使用日历 API,如 this article.
我还发现 this article 建议 修补 支持发送邀请的事件 - 结果是一样的,但仍然不适用于非 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");
这个:
sendNotifications: true, // 通过电子邮件发送邀请
应设置为请求参数,而不是事件主体的一部分。
Calendar.Events.insert(事件、日历、{sendNotifications:true})
我创建了一个 Google 表单,在提交时将信息输入 Google Sheet。
我创建了一段 Google Apps 脚本代码,该代码在提交时运行,创建日历事件并使用高级日历 API 在非主要 Google 我在表单所有者的 Google 帐户中创建的日历。
作为活动对象的一部分,我设置了一个 attendees
属性 收件人电子邮件地址数组,用于接收活动邀请。
我还将 sendNotifications
设置为 true。
当通过 API 创建事件时,我可以看到事件是在我指定的日历中创建的。 与会者列表中填充了我指定的收件人电子邮件地址。
拥有 Google 帐户的收件人会将日历事件作为暂定约会直接添加到他们的日历中。 非Google 收件人(例如 Hotmail 用户、Exchange 用户、Office 365 等)不会 收到邀请。
此外,通过日历 UI 编辑创建的事件会提示我进行 "update guests" 更改。确认这会使非 Google 收件人成功收到事件更改的电子邮件通知。 此外,直接通过日历 UI 创建活动并指定非 Google 与会者也会导致邀请成功发送。
只是通过日历创建事件API 似乎不起作用。
更复杂的是,如果我访问 Google events reference page,并使用 Try it! 表单(使用 OAuth 连接到 API)然后我可以 post 数据到 API 并成功收到来自非 Google 地址的活动邀请。
我想我 可以 连接某种 Google API 服务帐户,写一些 Google Apps 脚本代码来授权该服务帐户通过 OAuth 插件,并尝试通过某种外部 API 请求调用 API 到 Google 日历 API - 但我不确定如果这可行,我将不得不弄清楚如何从 Google Apps 脚本中获取 OAuth 内容。尽管如此,当 Google Apps 脚本支持在内部使用日历 API 时,似乎有点过分。
补充一下:我已经授权脚本通过脚本编辑器的高级 Google 服务区域以及开发人员控制台使用日历 API,如 this article.
我还发现 this article 建议 修补 支持发送邀请的事件 - 结果是一样的,但仍然不适用于非 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");
这个:
sendNotifications: true, // 通过电子邮件发送邀请
应设置为请求参数,而不是事件主体的一部分。
Calendar.Events.insert(事件、日历、{sendNotifications:true})