脚本超过driveWriteVolume rateMax

时间:2013-05-24 23:30:50

标签: google-apps-script gmail google-sheets google-apps

我有一段代码可以为线程中的每封电子邮件创建一个文件夹,并将正文(作为pdf)和所有附件(不管它们是什么)保存到该文件夹​​中。

如果我在没有循环的情况下运行它来保存附件,我没有问题。 (好吧,我对另一个线程有不同的问题)。如果我取消注释附件循环,我会得到

Service invoked too many times in a short time: driveWriteVolume rateMax. Try Utilities.sleep(1000) between calls. (line 156, file "Code")

创建文件夹或文件的所有行后跟Utilities.sleep(sleepTime);,睡眠时间当前设置为1000.更改它似乎没有任何效果。

令人讨厌的代码是:

        // Save attachments
        for(var i = 0; i < messageAttachments.length; i++) {
          var attachmentBlob = messageAttachments[i].copyBlob();
          newFolder.createFile(attachmentBlob);
          Utilities.sleep(sleepTime);  // wait after creating something on the drive.
        } // each attachment

触发错误的是newFolder.createFile(attachmentBlob);行。

我已查看What is driveWriteVolume rateMax?Intermittant DriveWriteVolume rateMax exception寻求帮助,但未找到任何帮助。

请注意,如果我注释掉附件的循环,只是将邮件正文保存为PDF,我就没有问题,无论我保存的电子邮件数量是多少。当我收到错误时,脚本已经死在应该保存第一个附件的位置。所以我认为除了超出某种限制之外还有其他错误。

1 个答案:

答案 0 :(得分:0)

你的命中率。谷歌api可能有大约20写/分钟的限制,所以你需要减慢你的脚本速度,以避免触发速率限制。在What is driveWriteVolume rateMax?中,类似线程中的用户使用3000毫秒的时间来解决问题,而不是建议的1000毫秒。

相关问题