Skip to content
Advertisement

Getting google calendar, “Service accounts cannot invite attendees without Domain-Wide Delegation of Authority.”

I can create events but when add attendees it returns this error i followed google guide and every thing is done but i can’t figure out what the problem

My code

<?php

require_once(APP_LIB.'google-api/vendor/autoload.php');

$client = new Google_Client();
//The json file you got after creating the service account
putenv('GOOGLE_APPLICATION_CREDENTIALS=checkup-project-298014-b11ac6f73f7b.json');
$client->useApplicationDefaultCredentials();
$client->setApplicationName("test_calendar");
$client->setScopes(Google_Service_Calendar::CALENDAR);
$client->setAccessType('offline');

$service = new Google_Service_Calendar($client);

$event = new Google_Service_Calendar_Event(array(
    'summary' => 'Test Test',
    'location' => 'Test Test',
    'description' => 'Hello world',
    'start' => array(
        'dateTime' => '2020-12-18T20:00:00+01:00',
        'timeZone' => 'America/Los_Angeles',
    ),
    'end' => array(
        'dateTime' => '2020-12-18T21:20:00+01:00',
        'timeZone' => 'America/Los_Angeles',
    ),
    'attendees' => array(
        array('email' => 'yasenabdelghany2222@gmail.com'),
    ),
));

$calendarId = 'xxxxxxxxx';
$event = $service->events->insert($calendarId, $event);

printf('Event created: %s', $event->htmlLink);

$conference = new Google_Service_Calendar_ConferenceData();
$conferenceRequest = new Google_Service_Calendar_CreateConferenceRequest();
$conferenceRequest->setRequestId('randomString123');
$conference->setCreateRequest($conferenceRequest);
$event->setConferenceData($conference);

// ['conferenceDataVersion' => 1] is required!
$event = $service->events->patch($calendarId, $event->id, $event, ['conferenceDataVersion' => 1]);

printf('<br>Conference created: %s', $event->hangoutLink);


// printf('Event created: %sn', $createdEvent->htmlLink);

I’m using google-api-php-client

the error:

GoogleServiceException: { “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.” } } in C:wampwwwbbb.portal.pfhcheckups.comappgoogle-apisrcHttpREST.php on line 128

Advertisement

Answer

Service accounts cannot invite attendees without Domain-Wide Delegation of Authority

Means exactly that. Only service accounts which have had domain wide delegation set up on the Gsuite (WorkSpace) domain can invite people to events.

Ask your Gsuite admin to set up domain wide delegation to the service account. If you dont have a gsuite domain either get one or use Oauth2 to authenticate a user instead of service accounts.

If you have delegated domain-wide access to the service account and you want to impersonate a user account, specify the email address of the user account using the method setSubject:

$client->setSubject($user_to_impersonate);
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement