Revert: remove attendee invitations from calendar events

Google API forbids attendees on service account events without
Domain-Wide Delegation (requires Google Workspace). Reverts to
direct event creation which works with personal Gmail calendars.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 14:58:45 +01:00
co-authored by Claude Sonnet 4.6
parent 06e25183da
commit 3561aa30bb
2 changed files with 12 additions and 28 deletions
+8 -24
View File
@@ -27,30 +27,19 @@ class GoogleCalendar {
}
/**
* Create a calendar event and notify the attendee.
* @param string $calendarId Calendar to insert into
* @param string $title
* @param string $description
* @param string $startDatetime ISO 8601 (e.g. 2026-03-10T10:00:00)
* @param string $endDatetime
* @param string|null $attendeeEmail If set, added as attendee — triggers push notification + invite email
* Create a calendar event.
* @return string|null The new event ID, or null on failure.
*/
public function createEvent($calendarId, $title, $description, $startDatetime, $endDatetime, $attendeeEmail = null) {
public function createEvent($calendarId, $title, $description, $startDatetime, $endDatetime) {
if (!$this->service || empty($calendarId)) return null;
try {
$eventData = [
$event = new Google_Service_Calendar_Event([
'summary' => $title,
'description' => $description,
'start' => ['dateTime' => $startDatetime, 'timeZone' => 'Europe/Oslo'],
'end' => ['dateTime' => $endDatetime, 'timeZone' => 'Europe/Oslo'],
];
if (!empty($attendeeEmail)) {
$eventData['attendees'] = [['email' => $attendeeEmail]];
}
$event = new Google_Service_Calendar_Event($eventData);
$params = !empty($attendeeEmail) ? ['sendUpdates' => 'all'] : [];
$result = $this->service->events->insert($calendarId, $event, $params);
]);
$result = $this->service->events->insert($calendarId, $event);
return $result->getId();
} catch (Exception $e) {
return null;
@@ -58,11 +47,10 @@ class GoogleCalendar {
}
/**
* Update an existing calendar event and notify the attendee.
* @param string|null $attendeeEmail If set, added as attendee — triggers update notification
* Update an existing calendar event.
* @return string|null The event ID, or null on failure.
*/
public function updateEvent($calendarId, $eventId, $title, $description, $startDatetime, $endDatetime, $attendeeEmail = null) {
public function updateEvent($calendarId, $eventId, $title, $description, $startDatetime, $endDatetime) {
if (!$this->service || empty($calendarId) || empty($eventId)) return null;
try {
$event = $this->service->events->get($calendarId, $eventId);
@@ -76,11 +64,7 @@ class GoogleCalendar {
'dateTime' => $endDatetime,
'timeZone' => 'Europe/Oslo',
]));
if (!empty($attendeeEmail)) {
$event->setAttendees([new Google_Service_Calendar_EventAttendee(['email' => $attendeeEmail])]);
}
$params = !empty($attendeeEmail) ? ['sendUpdates' => 'all'] : [];
$result = $this->service->events->update($calendarId, $eventId, $event, $params);
$result = $this->service->events->update($calendarId, $eventId, $event);
return $result->getId();
} catch (Exception $e) {
return null;