javascript - 如果设置公开并且组织中的所有 ID 均可访问,则 getCalendarById(id) 如何工作

标签 javascript web google-apps-script calendar google-calendar-api

我正在使用谷歌应用程序脚本来处理日历事件, 根据文件:https://developers.google.com/apps-script/reference/calendar/calendar-app#getCalendarById%28String%29

返回值为给定ID的日历,如果日历不存在或用户无法访问,则返回null 假设在一个组织 windows.com 中进行了设置,其中该组织中的所有 id 都可以访问,

var cal = CalendarApp.getCalendarById('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0b666a684b7c62656f647c7825686466" rel="noreferrer noopener nofollow">[email protected]</a>');
   Logger.log(cal);

如果我运行该函数并且手动订阅 [email protected] ,它会给出 null到授权脚本运行程序的日历然后它就可以正常工作,

有没有一种方法可以让我们在运行脚本时获取组织订阅的id,以便动态输入id。

组织 Google Business 应用中的日历设置为:默认与组织 windows.com 中的每个人共享此日历。

最佳答案

我在最近的项目中遇到了同样的问题,并发现用户必须显式订阅日历才能使 GetCalendarById 函数可靠地工作。我使用以下代码来处理此问题,如果 getCalendarById 第一次尝试返回失败,它会尝试订阅用户。

我还将日历设置为隐藏和未选择,因此订阅用户不会扰乱他们的标准日历 View 。

  var calendar = CalendarApp.getCalendarById(calendar_id);
  if(calendar == null){
    //user may not have access, auto-subscribe them.
    calendar = CalendarApp.subscribeToCalendar(calendar_id,{hidden:true,selected:false});
  }

请参阅calendarApp引用,https://developers.google.com/apps-script/reference/calendar/calendar-app#subscribeToCalendar(String,Object)

关于javascript - 如果设置公开并且组织中的所有 ID 均可访问,则 getCalendarById(id) 如何工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26645439/

相关文章:

google-apps-script - Google Apps 脚本 : `Those rows are out of bounds.` error

javascript - 使用 json 对象预填充表单的值

javascript - 如何保护我的 php、jquery、ajax 请求免受黑客攻击?

javascript - 拉斐尔多次移动

html - 如何将我的 Logo 从左侧移开 18 像素?

java - 想要创建一个表单填充器 - java、jsp、html 就够了吗?

ios - 如何将网站转换为 iOS 应用程序

google-apps-script - 如何替换已弃用的 DocsList 服务?

javascript - 有没有办法优化这个脚本以使其运行得更快?我收到错误 "Exceeded maximum execution time"

javascript - Uncaught ReferenceError : TweenLite is not defined