如果我有日历 ID,部署脚本以更改其他用户的 Google 日历的最佳方式是什么?
Best way to deploy a script to make changes to OTHER users's Google Calendar if I have calendarIDs?
我目前有一个 sheets-bound 脚本,它读取传播sheet 数据并根据 sheet 创建日历事件。该 spreadsheet 还存储了其他用户的 calendarID(不属于我),我正在尝试 read/write 他们的 google 日历。
我理想的使用流程是单个用户可以为所有存储的用户触发脚本,或者每个用户都可以单击脚本并将他们的事件添加到他们指定的日历中,但我发现我什至无法访问其他人的日历只有他们的 calendarIDs。
我在另一个 google 帐户上创建测试日历后,我的代码早些时候崩溃了。我将日历切换为 public,现在至少如 getEvents() 文档所示为空。然后我订阅了那个日历并收到了 "exception: Action not allowed".
我遇到了 OAuth2,觉得这是我需要以某种方式实现的东西,但我不确定如何去做。 我是否可以从脚本更改多个用户的日历,或者我是否需要了解网络应用程序,这是否允许我以某种方式访问其他人的日历?
编辑:我不是域用户,只是使用私人 google 帐户
编辑 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:"")});
}
也许避免编码 OAuth 流入您的应用程序的一个好方法是将脚本部署为 Web app 并使用 "Execute the app as: User accessing the web app"[=16 的选项部署它=].
当用户从您的网络应用程序发出请求时,您的网络应用程序的同意屏幕会弹出,用户必须同意,此后,此脚本将以用户身份运行,并可以使用 CalendarApp 将事件添加到他们的日历中。
我目前有一个 sheets-bound 脚本,它读取传播sheet 数据并根据 sheet 创建日历事件。该 spreadsheet 还存储了其他用户的 calendarID(不属于我),我正在尝试 read/write 他们的 google 日历。
我理想的使用流程是单个用户可以为所有存储的用户触发脚本,或者每个用户都可以单击脚本并将他们的事件添加到他们指定的日历中,但我发现我什至无法访问其他人的日历只有他们的 calendarIDs。
我在另一个 google 帐户上创建测试日历后,我的代码早些时候崩溃了。我将日历切换为 public,现在至少如 getEvents() 文档所示为空。然后我订阅了那个日历并收到了 "exception: Action not allowed".
我遇到了 OAuth2,觉得这是我需要以某种方式实现的东西,但我不确定如何去做。 我是否可以从脚本更改多个用户的日历,或者我是否需要了解网络应用程序,这是否允许我以某种方式访问其他人的日历?
编辑:我不是域用户,只是使用私人 google 帐户
编辑 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:"")});
}
也许避免编码 OAuth 流入您的应用程序的一个好方法是将脚本部署为 Web app 并使用 "Execute the app as: User accessing the web app"[=16 的选项部署它=].
当用户从您的网络应用程序发出请求时,您的网络应用程序的同意屏幕会弹出,用户必须同意,此后,此脚本将以用户身份运行,并可以使用 CalendarApp 将事件添加到他们的日历中。