简体   繁体   中英

Google Calendar API Invite to Existing Event

I am trying to determine a method for inviting guests to an already created event using Google Script or Google Calendar API. just using addGuest(email) doesn't send an email invite when adding a guest after the event is created.

Is this the way to go about it?

var calid = 'some CalendarID';
var eventid = 'some eventid';
var ss = SpreadsheetApp.getActiveSpreadsheet();
var column = ss.getRange('A2:A2');
var emails = column.getValues();
var createdEvent = Calendar.Events.update(calid, eventid).attendees(emails);

I also saw this but it doesn't work.

function sendInvite(calendarId, eventId, emails) {
  var event = Calendar.Events.get(calendarId, eventId);
  event.attendees.push({email: emails});
  event = Calendar.Events.patch(event, calendarId, eventId, {
    sendNotifications: true
  });
}

And this one:

function sendInvite(calendarId, eventId, email) {
var event = Calendar.Events.get(calendarId, eventId);
if(event.attendees) {
  event.attendees.push({
    email: email
  });
} else {
  event.attendees = new Array({email: email});
}
event = Calendar.Events.patch(event, calendarId, eventId, {
  sendNotifications: true
});
}

Turns out the Google event prevents the sending of past events by email. I was using a past date to test with. When I changed to a date in the future it worked great.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM