How to add add “Invite Me” link in Google Calendar

前端 未结 2 848
醉酒成梦
醉酒成梦 2021-01-14 17:34

I\'ve found someone adding \"Invite Me\" link in the Google Calendar as shown below. I\'ve tried my best but could not find a way to add this link when someone clicks on an

相关标签:
2条回答
  • 2021-01-14 18:29

    Try to use "setAnyoneCanAddSelf(anyoneCanAddSelf)"

    https://developers.google.com/apps-script/reference/calendar/calendar-event?hl=es#setAnyoneCanAddSelf(Boolean)

    0 讨论(0)
  • 2021-01-14 18:34

    Molk is correct, you will need to setAnyoneCanAddSelf(true).

    How I would go about it is deploying a script as a web app that takes a query parameter for the calendar event id, the Session.getActiveUser().getEmail(), and add them to the calendar event. I would create the URL in the primary calendar's Description field (like your screenshot, with the url to the deployed script url and adding the query parameter for the id.

    An example would look something like this:

    var calId = 'yourdomain.com_459nd7pqmn5irsqgn8p91febe4@group.calendar.google.com';
    
    function inviteMe(){
      try{
        var cal = CalendarApp.getCalendarById(calId);
        var start = new Date();
        var end = new Date();
        start.setHours(13);
        end.setHours(14);
    
        var event = cal.createEvent("Add Me Test", start,end);
        event.setAnyoneCanAddSelf(true);
        var eventId = event.getId();
        var urlString = '<a href="' + ScriptApp.getService().getUrl() +'?eId=' + eventId + '" target="_blank">Invite Me</a>';
        var desc ='Event details';
        desc += '\n\n' + urlString;
        // now that we have the url built out, add the description
        event.setDescription(desc);
      }catch(err){
        Logger.log(err.lineNumber + ' - ' + err);
        ;
      }
    }
    
    function doGet(event){
      try{
        // shorten the event parameter path;
        var param = event.parameter;
        // get the calendar event id passed in the query parameter
        var eventId = param.eId;
        var cal = CalendarApp.getCalendarById(calId);
        var guest = Session.getActiveUser().getEmail();
    
        var event = cal.getEventSeriesById(eventId);
        event.addGuest(guest);
    
        return ContentService.createTextOutput("You have been added to the event: " +         event.getTitle());
      }catch(err){
        Logger.log(err.lineNumber + ' - ' + err);
      }
    }
    

    And how it would look would be something like this: In the event details, click the invite me link invite me

    Once Processed, use ContentService to display a notice. enter image description here

    And finally see the calendar in the users calendar completed entry

    The event owner will not see the link in their description area, only the raw html anchor text (see screenshot below). Google Calendar renders the link for everyone else; I assume for ease of editing, since the description field is just a textarea input, with no WYSIWYG controls. Event Owner's View

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