【问题标题】:Generating multiple calendars in iframe在 iframe 中生成多个日历
【发布时间】:2015-09-07 01:11:58
【问题描述】:

我有一个用于教育的谷歌应用程序帐户和一个在小工具内运行的应用程序脚本,它获取用户所属/拥有的所有日历。然后我根据他们的角色生成 url。管理员用户似乎可以看到他们所有的日历,但普通用户需要专门点击“订阅日历”或访问https://www.google.com/calendar/render#main_7,然后重新加载小工具才能查看他们的日历。

 if (role == "student") {
    url = "https://www.google.com/calendar/embed?        
    showTitle=0&showTabs=1&showCalendars=1&height=600&wkst=2&mode=DAY&showTitle=0&" +         replaceStr + "&ctz=Australia%2FVictoria&dates=" + startDate + "/" + startDate;
   } else if (role == "parent") {
  url = "https://www.google.com/calendar/embed?showTitle=0&showTabs=1&showCalendars=1&height=600&wkst=2&mode=MONTH&showTitle=0&"    + replaceStr + "&ctz=Australia%2FVictoria&dates=" + startDate + "/" + startDate;
     } else if (role == "teacher") {
  url = "https://www.google.com/calendar/embed?showTitle=0&showBorderTitle=1&showTabs=1&showCalendars=1&height=600&wkst=2&mode=WE   EK&showTitle=0&" + replaceStr + "&ctz=Australia%2FVictoria&dates=" + startDate +  "/" + startDate;
    } else {
 url = "https://www.google.com/calendar/embed?showTitle=0&showBorderTitle=1&showTabs=1&showCalendars=1&height=600&wkst=2&mode=MO  NTH&showTitle=0&" + replaceStr + "&ctz=Australia%2FVictoria&dates=" + startDate + "/" + startDate;
 }

这是获取所有用户日历的代码:

var calendars = CalendarApp.getAllCalendars();
 var calendarIDs = [];
 for (var i=0;i<calendars.length;i++) {
  calendarIDs.push(calendars[i].getId()); 
 }
 Logger.log(calendarIDs);
 return calendarIDs;
} 

有没有办法解决这个问题?我尝试了谷歌日历权限,编辑 url 参数并使用 UrlFetchApp 在我的应用程序脚本中获取https://www.google.com/calendar/render#main_7 以异步加载页面但没有成功。任何建议或是否有人遇到与此相同的问题将不胜感激。

更新 我可以显示用户拥有的日历,但除非执行上述过程,否则无法查看与所有域用户共享的日历。我们是否无法显示不公开且不归用户所有、仅共享的日历?

【问题讨论】:

  • 我不确定我是否在您的帖子中看到了问题?
  • 对不起,我会尽快澄清

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


【解决方案1】:

问题在于两个不允许嵌入的日历。这些是联系人日历和假期日历。一旦我将这些从 replaceStr 字符串中取出,我就能够在 GAS iframe 中成功加载我的所有日​​历(最多 16 个)。

更正的代码:

var calendars = CalendarApp.getAllCalendars();
          var calendarIDs = [];
          var notCalendarIDs = [];   
          for (var i=0;i<calendars.length;i++) {
              Logger.log("All calendars " + calendars[i].getId());

              if (calendars[i].getId() != "en.australian#holiday@group.v.calendar.google.com" && calendars[i].getId() != "#contacts@group.v.calendar.google.com") {
                 calendarIDs.push(calendars[i].getId());
              } 
         }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-10
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 2018-07-14
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多