google-apps-script - 同步从 URL 创建的 Google 日历
问题描述
我已经使用 URL https://calendar.google.com/calendar/u/0/r/settings/addbyurl手动将我的健身房日历添加到我的谷歌日历中,并粘贴到健身房的 webcal url 中。这有效,新日历在谷歌日历中显示为“其他日历”。但是,当我预订更多的体育课时,它们并没有被谷歌同步。
如果我手动取消订阅“其他日历”并重新创建它,新的健身课程会出现在我的桌面和我的安卓手机上。这种娱乐迫使同步。
所以我尝试编写一些谷歌应用脚本来删除“其他日历”并重新创建它。然后通过基于时间的触发器运行应用脚本。
该脚本运行正常并且删除工作有效,但我找不到通过脚本重新创建日历的方法。所以我真的很感激一些帮助来完成这个编码或强制谷歌日历重新同步它的“其他日历”(无论如何它应该这样做)。
这是我的编码:
myCalendar('My Bookings');
function myCalendar(mycal) {
var calendars;
var pageToken;
do {
calendars = Calendar.CalendarList.list({
maxResults: 100,
pageToken: pageToken
});
if (calendars.items && calendars.items.length > 0) {
for (var i = 0; i < calendars.items.length; i++) {
var calendar = calendars.items[i];
Logger.log('%s (ID: %s)', calendar.summary, calendar.id, calendar.description);
if (calendar.summary == mycal) {
// get works it's my gym calendar, but why doesn't it show the webcal url?
var mycalendar = Calendar.CalendarList.get(calendar.id);
Logger.log(mycalendar);
// remove works
Calendar.CalendarList.remove(calendar.id);
Logger.log('removed');
// The calendar has been removed
// But how do I recreate the same calendar from a url?
}
}
} else {
Logger.log('No calendar found.');
}
pageToken = calendars.nextPageToken;
} while (pageToken);
}
解决方案
这段代码按你说的做。
function myFunction () {
var id = 'nmkf37p4k6onnhsa8a770u0m8adqd3v2@import.calendar.google.com'
//change this id.
//You can find your calendar's id in Calendar Settings > Integrate Calendar
var calendar = CalendarApp.getCalendarById(id)
calendar.unsubscribeFromCalendar() // this line makes you unsubscribe
CalendarApp.subscribeToCalendar(id) // this makes you resubscribe
}
但是请告诉我,您如何将新事件添加到日历中?例如,您通过calendar.google.com
浏览器添加它们,但在 Android 手机上看不到它们。这是正在发生的事情吗?
推荐阅读
- c - c中的文件解析,如果存在则提取特定行
- flutter - 如何在 Flutter 中实现这种设计?
- node.js - 使用 npx create-react-app 创建 React 应用程序很慢,有什么方法可以加快速度吗?
- mysql - 如何在 MYSQL 查询中的 UPDATE 内部进行 SELECT
- regex - 替换 '\n' 前后的字符串正则表达式的一般解决方案
- javascript - 从元素接收文本
- dart - 如何在 Dart 中将二进制代码转换为数字
- python - 从十六进制转换为颜色名称 Python
- python - 在Python中的文本文件中逐行查找行尾
- django - 为什么我在将文件上传到互联网速度较慢的服务器时收到 ERR_HTTP2_PING_FAILED?