Create an event with an attachment on Calendar via Google apps script

前端 未结 1 631
轻奢々
轻奢々 2021-01-20 16:17

I couldn\'t find a way to add an attachment to my calendar event. I hope there should be a simple way like below snippet,

function createNewEvent()
{
 var fi         


        
相关标签:
1条回答
  • 2021-01-20 17:05

    Yes, this is possible. First you must enable the Advanced Calendar Service. Then you can do something like this:

    function createNewEvent() {
      var calendarId = ''; //Calendar Id String
      var fileId = ''; // File Id String
      var start = new Date('January 20, 2016 20:00:00 UTC');
      var end = new Date('January 20, 2016 21:00:00 UTC');
      var eventObj = {
        summary: 'Apollo 11 Landing',
        location: 'The Moon',
        description: 'Sample description',
        start: {dateTime: start.toISOString()},
        end: {dateTime: end.toISOString()},
        attachments: [{
            'fileUrl': 'https://drive.google.com/open?id=' + fileId,
            'title': 'Moon Docs'
        }]
      };
      var resp = Calendar.Events.insert(eventObj, calendarId, {'supportsAttachments': true});
      Logger.log(resp); // Check out the response in the logs!
    }
    

    For more options, check out the Events documentation.

    0 讨论(0)
提交回复
热议问题