Google Script说:您在短时间内创建或删除了太多日历或日历活动。请稍后再试

时间:2015-08-26 15:06:18

标签: google-apps-script google-api google-sheets google-calendar-api

我收到了这个非常令人沮丧的错误。我绝不会创建或删除太多日历 - 最多我创建了大约20个日历,而我的脚本只是尝试创建一个日历!

我已将问题缩小到event.addGuests()。当我删除此行时,会添加该事件。当我保留它时,这就是Google报告错误的地方。

我已尝试添加

Utilities.sleep(5000);
event.addGuest()之前

查看减慢脚本速度是否有效,但这也不起作用。

这是整个脚本。请注意,现在电子表格中只有一个项目

var ACCEPTED = "ACCEPTED";
var PUBLISHED = "PUBLISHED"
var NOT_PUBLISHED = "NOT_PUBLISHED";


function createCalendarEventsFromSheets(){
  // Get Calendar Info
  var calId = "privatecalendar@group.calendar.google.com";// use default claendar for tests
  var cal = CalendarApp.getCalendarById(calId);

  // Get Google Sheet Info
  var ss = SpreadsheetApp.openById('privatespreadhseet');
  var sheet = ss.getSheets()[0];
  var range = sheet.getDataRange();
  var rows = range.getValues();
  Logger.log("Rows found: " + rows.length);
  // Iterate through Google Sheets rows and create events
  for (i = 1; i < rows.length; i++){
    var row  = rows[i];
    // Gather variables for row
    var eventTitle = row[1];
    var date       = new Date(row[2]);
    var location   = row[3];
    var shiftStart = row[4];
    var shiftEnd   = row[5];
    var eventStart = row[6];
    var eventEnd   = row[7];
    var numberOfKeys = row[8];
    var role       = row[9];
    var notes      = row[10];
    var accepted   = row[13];
    var alreadyPublished = row[14]

    // If event has been accepted and wasn't published yet, create event
    Logger.log("accepted: " + accepted + ", alreadyPublished " + alreadyPublished);

    if (accepted == ACCEPTED && alreadyPublished != PUBLISHED){
      Logger.log("**** TRUE ****");
      // Set up calendar event
      var cal_start = new Date(date.getYear(), date.getMonth(), date.getDate(), shiftStart.getHours(), shiftStart.getMinutes());
      Logger.log("cal_start: " + cal_start);
      var cal_end = new Date(date.getYear(), date.getMonth(), date.getDate(), shiftEnd.getHours(), shiftEnd.getMinutes());
      Logger.log("cal_end: " + cal_end);

      var description = "Keys Required: " + numberOfKeys + "\n\nRole: " + role + "\n\nEvent Start Time: " + eventStart.getHours() + ":" + eventStart.getMinutes() + ", Event End Time: " + eventEnd.getHours() + ":" + eventEnd.getMinutes() + "\n\nNotes:\n" + notes;

      // CREATE EVENT
      var event = cal.createEvent(eventTitle, cal_start, cal_end);

      event.setDescription(description);
      event.setLocation(location);
      //Utilities.sleep(5000); // I've tried this, to no avail
      event.addGuest("rap@gmail.com"); //error message details point to here
      event.addGuest('e.leg@gmail.com');
      event.addGuest('ba@hotmail.com');
      event.addGuest('r@hotmail.com');
      event.addGuest('js@gmail.com');
      event.addGuest('w@gmail.com');
      event.addGuest('no.abe@gmail.com');
      event.addGuest('esth@gmail.com');
      event.addGuest('carolin@gmail.com');
      event.addGuest('kalan@gmail.com');
      event.addGuest('bob@gmail.com');
      event.addGuest('rob@gmail.com');

      sheet.getRange(i+1, 15).setValue(PUBLISHED);
      Logger.log("Event created, starting at: " + event.getStartTime());

    }
  }
}

0 个答案:

没有答案