2015-09-07 48 views
0

我有一個用於教育帳戶和應用程序腳本的Google應用程序,該應用程序腳本在小工具中運行,可以獲取用戶所有/擁有的所有日曆。然後,我根據他們的角色生成網址。看起來,管理員用戶可以看到他們的所有日曆,但普通用戶需要專門點擊「訂閱日曆」或訪問https://www.google.com/calendar/render#main_7,然後重新加載小工具才能查看他們的日曆。在iframe中生成多個日曆

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以異步加載頁面而沒有成功。任何意見,或如果任何人有這樣的問題將不勝感激。

UPDATE我能夠顯示用戶擁有的日曆,但共享給所有域用戶的日曆無法查看,除非執行上述過程。我們是否無法顯示不公開且不屬於用戶所有的日曆,只能共享?

+0

我不知道我在您的文章看問題的任何地方? – dman2306

+0

對不起,我會盡快澄清 – Tyron

回答

0

問題在於兩個日曆不允許嵌入。這些是聯繫人日曆和假日日曆。一旦我將這些從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#[email protected]" && calendars[i].getId() != "#[email protected]") { 
       calendarIDs.push(calendars[i].getId()); 
       } 
     }