【问题标题】:How to add add "Invite Me" link in Google Calendar如何在 Google 日历中添加“邀请我”链接
【发布时间】:2014-08-11 04:17:48
【问题描述】:

我发现有人在 Google 日历中添加了“邀请我”链接,如下所示。我已经尽力了,但是当有人点击某个事件时找不到添加此链接的方法。

【问题讨论】:

    标签: google-apps-script google-calendar-api


    【解决方案1】:

    Molk 是正确的,你需要 setAnyoneCanAddSelf(true)。

    我将如何着手将脚本部署为 Web 应用程序,该应用程序接受日历事件 ID 的查询参数 Session.getActiveUser().getEmail(),并将它们添加到日历事件中。我会在主日历的描述字段中创建 URL(就像您的屏幕截图一样,使用已部署脚本 url 的 url 并添加 id 的查询参数。

    示例如下所示:

    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);
      }
    }
    

    它看起来会是这样的: 在活动详情中,点击邀请我链接

    处理后,使用 ContentService 显示通知。

    最后在用户日历中查看日历

    事件所有者将不会在他们的描述区域中看到链接,只会看到原始的 html 锚文本(请参见下面的屏幕截图)。谷歌日历为其他人呈现链接;我假设是为了便于编辑,因为描述字段只是一个文本区域输入,没有所见即所得的控件。

    【讨论】:

    • 你能告诉你如何得到你展示的活动细节吗?在我的日历页面中,我无法像这样显示它:没有 HTML 渲染。我在 Mac OS 上使用 chrome。
    • Google 将原始 html 锚文本呈现为访问者的实际链接,但将其显示为事件所有者的直接文本。我会用截图更新帖子。
    • 从哪里调用这个函数“inviteMe”?
    • inviteMe() 只是一个创建日历事件的函数。我包含它是为了展示一种编程方式来创建事件并为邀请我链接构建 url。如果您已经创建了事件,您可以修改代码以迭代现有事件,获取它们的事件 ID,并添加邀请我链接。
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 2014-03-31
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      相关资源
      最近更新 更多