目前,我有一個工作表綁定腳本,用于讀取電子表格數據并根據工作表創建日歷事件。該電子表格還存儲了其他用戶的日歷ID(不屬于我),我正在嘗試讀取/寫入他們的Google日歷。我理想的使用流程是,單個用戶可以為所有存儲的用戶觸發腳本,或者每個用戶都可以單擊腳本并將其事件添加到其指定的日歷中,但我發現我甚至無法僅使用其 calendarID 訪問其他人的日歷。在我在另一個Google帳戶上創建測試日歷后,我的代碼早些時候崩潰了。我將日歷切換為公共日歷,現在至少按照 getEvents() 文檔的指示獲得空值。然后,我訂閱了該日歷,并收到了“例外:不允許操作”。我遇到了OAuth2,覺得這是我需要以某種方式實現的東西,但我不確定如何去做。我是否可以從腳本中對多個用戶的日歷進行更改,或者我是否需要了解Web應用程序,這是否允許我以某種方式訪問其他人的日歷?編輯:我不是域名用戶,只是使用私人個人谷歌帳戶編輯2:還發現附加組件是一回事。去閱讀/**Function to add shift details to user's calendar@param{object} user-object with keys of column header's of user-info sheet (name, email, year, calName, calID, early, late)@param{object} eventDetails - an object with keys created after interpreting shift codes (title, start, end, location, desscription, problem, pdate, pvalue)*/function addToCalendar(user, eventDetails){ var calendar = CalendarApp.getCalendarById(user.calID); if(calendar == null){ Logger.log(user.name); //testing code, realized I couldn't accesss other's calIDs here } var existingEvents = calendar.getEvents(eventDetails.start, eventDetails.end); if(existingEvents.length>0){ if(existingEvents[0].getTitle() == eventDetails.title){ Logger.log("ALREADY CREATED!!"); return; } } calendar.createEvent(eventDetails.title, eventDetails.start, eventDetails.end, {description : (eventDetails.description ? eventDetails.description:""), location: (eventDetails.location ? eventDetails.location:"")}); }
如果我有日歷 ID,則部署腳本以對其他用戶的 Google 日歷進行更改的最佳方式?
素胚勾勒不出你
2022-09-23 09:18:11