使用Calendar API更改Google日历活动的忙/闲状态 [英] Change Google Calendar Event Free/Busy with Calendar API

查看:100
本文介绍了使用Calendar API更改Google日历活动的忙/闲状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于预订房间的GAS网络应用。当应用创建事件时,该事件当前默认为忙碌。我试图将默认设置为免费。

I have a GAS web app for reserving rooms. When the app creates the event, it currently defaults to "Busy" for the event. I am trying to set the default to "Free".

我找到了一个GAS论坛条目,建议使用Advanced Google Calendar API编辑透明度字段(来源: https://code.google.com/p/google-apps-script-issues/issues/detail ?id = 2341 )。

I found a GAS forum entry that recommends using the Advanced Google Calendar API to edit the transparency field (Source: https://code.google.com/p/google-apps-script-issues/issues/detail?id=2341).

他们建议的脚本是

var changes = {
transparency: "transparent"
};
Calendar.Events.patch(changes, cal_id, event_id);

我启用了高级API,但是由于某些原因,我在Chrome中收到未捕获的错误提示函数执行时进行控制台。关于此错误的来源有何想法?

I have the Advanced API enabled, but for some reason I am getting an uncaught error prompt in the Chrome console when the function executes. Any thoughts on where this error is coming from?

推荐答案

环顾四周后,似乎可以使用以下方法。我忘记了在向CalendarApi发出请求之前,您需要从CalendarApp返回的事件ID中删除 @ google.com。由于用户仅在自己的日历上编辑事件,因此calendarId可以设置为主要。

After looking around, the following seems to work. I forgot that you need to remove the "@google.com" from the event ID returned by CalendarApp before making a request to CalendarApi. The calendarId can be set to 'primary' since the user is only editing an event on their own calendar

var eventId= event_id.slice(0,event_id.length-11);
var calendarId = 'primary';
Logger.log(eventId)
var changes = {
    transparency: "transparent"
  };
Calendar.Events.patch(changes,calendarId,eventId);

这篇关于使用Calendar API更改Google日历活动的忙/闲状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆