I try to use the Google Calendar API by php running server side.
I created a service account and use its credentials (via the json file). I am NOT using G Suite.
Now I am able to list events of my calendar but I get a Forbidden - Error, when I try to create a new event.
I shared my calendar with the service account's email address and gave it admin rights for the calendar. I don't know what I am doing wrong! I just can't get it working. I am also using the scope Google_Service_Calendar::CALENDAR.
The exception: 403 - Forbidden
I have no idea how to debug this problem and how to proceed further.
Can you help me?
Edit: here is my calling code:
putenv('GOOGLE_APPLICATION_CREDENTIALS=../google-service-account.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes([Google_Service_Calendar::CALENDAR]);
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$service = new Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event([
'summary' => $name,
'location' => $location,
'description' => $desc,
'start' => [
'dateTime' => $start,
'timeZone' => $timezone,
],
'endTimeUnspecified' => true,
]);
$calendar = $service->calendars->get($calendarId);
$settings = $service->settings->listSettings();
$list = $service->acl->listAcl($calendarId);
$event = $service->events->insert($calendarId, $event);
The first three service calls ($calender = ...
, $settings = ...
and $list = ...
) work fine and in the acl I can also see that the email address of my service account has all rights (role: owner). But the last line $event = ...
gives the forbidden error...