You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Google Calendar API删除事件时遇语法错误求助

Fixing "Missing name after . operator" in Google Apps Script Calendar Delete Code

Hey there! Let's break down what's causing that syntax error and get your code working right away.

The Root Cause

The error Missing name after . operator pops up because delete is a reserved keyword in JavaScript. When you try to call calendar.events.delete(params, ...), the script interpreter gets confused—reserved words can't be used directly as property names with dot notation.

The Fix

Swap out the dot notation for bracket notation when accessing the delete method. Here's how to adjust that problematic line:

calendar.events['delete'](params, function(err) {
  if (err) {
    console.log('The API returned an error: ' + err);
    return;
  }
  // Replace ... with your actual success logic here
});

Bonus: Small Optimization

You're fetching calendarId = sheet.getRange('E2').getValue() inside your loop, but this value doesn't change between iterations. Move it outside the loop to make your code run more efficiently:

function deleteEvent() {
  // Get calendar ID once, outside the loop
  var calendarId = sheet.getRange('E2').getValue();
  for (var i = 1; i < datalastRow; i++) {
    var delete_eventid = sheet.getRange(i + 1, 3).getValue();
    var params = {
      calendarId: calendarId,
      eventId: delete_eventid,
    };
    calendar.events['delete'](params, function(err) {
      if (err) {
        console.log('The API returned an error: ' + err);
        return;
      }
      // Add your success handling code here
    });
  }
}

Quick Checks

  • Double-check that datalastRow and sheet are properly defined elsewhere in your script (they aren't included in your snippet, but we'll assume they're set up correctly).
  • Don't forget to replace the ... in your callback with the actual actions you want to run when an event is deleted successfully.

内容的提问来源于stack exchange,提问作者Aaron

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:59:25