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

通过Apps Script与Google Calendar API为Google Calendar活动添加多位参会者时的错误排查

Fix "Invalid attendee email" Error When Adding Multiple Attendees via Google Apps Script

The root cause of your GoogleJsonResponseException: Invalid attendee email error is how you're structuring the attendees array. Right now, you're passing entire arrays of emails and names to a single attendee object, but the Google Calendar API expects an array of individual attendee objects—each with a single string email and displayName.

Here's the breakdown of the mistake:

Your current code takes the split arrays and shoves them into one attendee entry:

var emails = attendeesEmail.split(",");
var names = attendeesNames.split(",");
const event = {
    // ... other properties
    'attendees': [
        { email: emails, displayName: names } // ❌ Passes arrays instead of individual strings
    ]
}

The Fix:

You need to loop through the split email and name arrays, create a separate attendee object for each pair, and collect those into the attendees array. Also, make sure to trim any extra whitespace from split values (since your example has ", " between entries, which leaves a leading space on the second name/email).

Replace your problematic code block with this:

// Handle attendees: split and clean up values, then create individual attendee objects
const attendees = [];
if (attendeesEmail && attendeesNames) {
    const emails = attendeesEmail.split(",").map(email => email.trim());
    const names = attendeesNames.split(",").map(name => name.trim());
    
    // Match each email to its corresponding name (assumes arrays are same length)
    for (let j = 0; j < emails.length; j++) {
        attendees.push({
            email: emails[j],
            displayName: names[j] || '' // Fallback to empty string if name is missing
        });
    }
}

const event = {
    id: eventID,
    summary: eventsubject,
    location: location,
    description: description,
    'start': {
        'dateTime': startTime.toISOString(),
        'timeZone': 'US/Central'
    },
    'end': {
        'dateTime': endTime.toISOString(),
        'timeZone': 'US/Central'
    },
    colorId: color,
    attendees: attendees // ✅ Pass array of individual attendee objects
}

Key Improvements:

  • Uses map().trim() to remove extra spaces from split values (critical for avoiding invalid emails with leading/trailing spaces)
  • Creates a dedicated attendees array by pairing each email with its matching name
  • Adds a fallback for missing names to prevent undefined values
  • Properly structures the attendees array to meet Calendar API requirements

Additional Checks:

  • Ensure that the number of names matches the number of emails in your spreadsheet rows (the code assumes they're paired correctly)
  • Test with both single and multiple attendee rows to confirm the fix works for both cases

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.27 10:17:34