通过Google Apps脚本将日历邀请发送到非Google帐户 [英] Sending calendar invites to non-Google accounts via Google Apps Script

查看:114
本文介绍了通过Google Apps脚本将日历邀请发送到非Google帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Google表单,用于在提交时向Google表单中输入信息。



我创建了一段在提交时运行的Google Apps脚本代码,它会创建一个日历事件并使用高级日历API在我在表单所有者的Google帐户中创建的非主要Google日历上创建事件。



作为事件对象的一部分,我将设置要接收事件邀请的收件人电子邮件地址的参与者属性数组。
我还将 sendNotifications 设置为true。



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



拥有Google帐户的收件人将直接添加日历活动作为暂定约会进入他们的日历。
非Google收件人(例如Hotmail用户,Exchange用户,Office 365等)仅收到邀请。



除此之外,通过日历UI编辑创建的事件会提示我更新客人的变化。确认这会导致非Google收件人成功收到事件更改的电子邮件通知。
此外,直接通过日历界面创建活动并指定非Google参与者也会导致邀请成功发送。



只需创建事件通过Calendar API似乎不起作用。



使事情进一步复杂化,如果我访问 Google events reference page ,并使用 Try it!表单(使用API​​连接OAuth),那么我可以将数据发布到API并成功接收来自非Google地址的事件邀请。



我想我可以 wire建立某种Google API服务帐户,编写一些Google Apps脚本代码以通过OAuth插件授权该服务帐户,并尝试通过某些外部API请求调用API到Google Calendar API - 但是,我不确定这是否会奏效,我必须弄清楚通过Google Apps脚本获取OAuth内容。即使如此,当Google Apps脚本支持在内部使用Calendar API时,似乎有点过分。



只需添加:我已授权脚本使用日历通过脚本编辑器的高级Google服务区以及开发人员控制台访问API,如这篇文章



我也发现这篇文章建议修补支持发送邀请的事件 - 结果是一样的,仍然不适用于非Google帐户。



我的代码如下所示:

  //设定变量
var appointmentWith =Nick W;
var location =会议室;
var description =向约会添加一些笔记;
var calendar =1v1 ..... u80@group.calendar.google.com; //日历的日历ID
/ *
joinedStart和endDate在别处设置
* /

//创建一个事件对象
var event = {
summary:appointmentWith,//预约的标题
location:location,//预约的位置
描述:描述//表单描述/提交的值
start:{
dateTime:joinedStart.toISOString()//约会的开始时间
},
end:{
dateTime:endDate.toISOString()//结束时间预约
},
sendNotifications:true,//通过电子邮件发送邀请
与会者:[
{email:recipient},//设置收件人电子邮件地址
{电子邮件地址:user@googleaccount.com},
{email:nongoogle-user@hotmail.com}
]
};



Logger.log(创建新的日历事件);
event = Calendar.Events.insert(event,calendar); //创建事件,但不会通知非Google电子邮件帐户
Logger.log(event.id);
Logger.log(新建日历事件);

//试图修补事件,希望能解决这个问题
Logger.log(send further invites);
event.attendees.push({email:user@hotmail.com});
event = Calendar.Events.patch(event,calendar,event.id,{sendNotifications:true});

Logger.log(sent);


解决方案

b $ b

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



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



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

I've created a Google Form that enters information into a Google Sheet on submitting.

I've created a piece of Google Apps Script code that runs on submit, that creates a Calendar Event and uses the Advanced Calendar API to create the event on a non-primary Google Calendar that I've created in the Form owner's Google account.

As part of the event object, I'm setting an attendees property array of recipient email addresses that are to receive invitations to the event. I'm also setting sendNotifications to true.

When the event is created via the API, I can see that the event is created in the calendar I've specified. The attendees list is populated with the recipient email addresses I've specified.

Recipients that have Google accounts will have the calendar event added as a tentative appointment directly into their calendar. Non-Google recipients (e.g. Hotmail users, Exchange users, Office 365 etc.) simply do not receive the invitation.

Further to this, editing the created event through the calendar UI prompts me to "update guests" of changes. Confirming this causes the non-Google recipient to successfully receive the email notification of the event change. Additionally, creating an event through the calendar UI directly and specifying the non-Google attendees also causes the invite to be delivered successfully.

It's just that creating the event through the Calendar API doesn't seem to work.

To complicate matters further, if I visit the Google events reference page, and use the Try it! Form (connecting to the API using OAuth ) then I can post data to the API and successfully receive an event invitation from a non-Google address.

I suppose I could wire up some sort of Google API Service Account, write some Google Apps Script code to authorize with that service account via an OAuth plug-in, and attempt to call the API via some sort of external API request to the Google Calendar API - but I'm unsure if this will work and I'd have to figure out how to get the OAuth stuff working from within Google Apps Script. Even so, it seems a little excessive when the Google Apps Script supports using the Calendar API internally anyhow.

Just to add: I've authorised the script to use the Calendar API via the Advanced Google services area of the Script Editor as well as the Developers Console, as recommended in this article.

I've also found this article which suggests patching an event to support sending invites - the result is the same and still doesn't work to non-Google accounts.

My code is as follows:

  // 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");

解决方案

This:

sendNotifications: true, // email the invite

should be set as a request parameter, not as a part of the Event body.

Calendar.Events.insert(event, calendar, {sendNotifications:true})

这篇关于通过Google Apps脚本将日历邀请发送到非Google帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆