1

我目前正在编写一个脚本,旨在在 6 个月内为 50 人编写 Google 日历,每天一个活动。这些事件可以有不同的开始/结束时间,也可以是全天事件。这些日历都将写入同一个 Google 帐户,用户将使用他们的个人帐户订阅它们。

日历的数据最初存储在 Google 电子表格中。我的脚本按照建议使用 getRange.getValues 方法一步读取此电子表格,但我找不到一种方法来“批量”写入,除非在 for 循环中使用 .createEvent 方法。由于运行时间过长(整个批次大约有 9000 个日历事件,超过了 5 分钟的范围),这个循环在运行的大约 1/10 处被杀死。

如果我注释掉 .createEvent 行,脚本运行得很好。

有没有办法优化对谷歌日历的写入(将数组传递给 .createEvent 或其他东西......)?

4

1 回答 1

0

There's no batch methods for the Calendar API. You have to insert one by one in the "slow" loop.

The solution I use in my scripts is to divide the load into "doable" chunks. You can save on each row if you have processed it or not, or you can save somewhere (e.g. a cell or script property) the row you stopped last. And then, configure your script to stop by itself when it has worked its share (e.g. 3000 events).

I'm not sure if you have seen it already, but there's a new dashboard where you can see that your quotas for the various APIs. It seems that after you solve this time limit quota, you'll run into the calendars. Good news is that this spread the load solution will also help you to deal with it.

于 2012-05-08T00:55:43.797 回答