3
votes

so i want send invitation email to attendees on an event created on google calendar. but when i did

use Spatie\GoogleCalendar\Event as GoogleCalendarEvent;

$calendarEvent = new GoogleCalendarEvent;

$calendarEvent->name = $event->title;
$calendarEvent->startDateTime = $event->start_date;
$calendarEvent->endDateTime = $event->end_date;
$calendarEvent->addAttendee(['email' => '[email protected]']);

$calendarEvent->save();

I get error as

{ "error": 
    { "errors": [{ 
         "domain": "calendar", 
         "reason": "forbiddenForServiceAccounts", 
         "message": "Service accounts cannot invite attendees without Domain-Wide Delegation of Authority." 
    } ], 
     "code": 403, 
     "message": "Service accounts cannot invite attendees without Domain-Wide Delegation of Authority." 
    } 
}

So I already gave a domain-wide authority to the service credential. But i am still getting the error because i tried to invite users using the service account. How can i impersonate a user using this service account in laravel 7 using Spatie\GoogleCalendar ?

I tried browsing google's api and Spatie's docs. but i can't find any

1

1 Answers

2
votes

This issue has been already reported on Google's Public Issue Tracker

Currently, a service account is not allowed to invite attendees without impersonation.

In order to implement impersonation, you need to add the line

$client->setSubject('SPECIFY HERE THE USER TO IMPERSONATE');

when creating new Google_Client() with the service account.

See here for more information.