I've been struggling with this problem for quite some time now. Basically, I have a website where the admin can create events, and at the same time, the events should be added to my company's Google Calendar. I have an HTML form, which posts information to a PHP file, which then attempts to add the event to my own Google Calendar. I've currently made a service account and this is what my code looks like:
require_once 'google-api/vendor/autoload.php';
$client = new Google_Client();
$client->setApplicationName("House Events");
$client->setAuthConfig("MY AUTH CONFIG FILE");
$client->setScopes(Google_Service_Calendar::CALENDAR);
$client->setAccessType('offline');
$service = new Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event(array(
'summary' => $title,
'description' => $html,
'start' => array(
'dateTime' => $start
),
'end' => array(
'dateTime' => $end
)
));
$calendarId = 'MY CALENDAR ID';
$event = $service->events->insert($calendarId, $event);
$calendarListEntry = new Google_Service_Calendar_CalendarListEntry();
$calendarListEntry->setId($calendarId);
$createdCalendarListEntry = $service->calendarList->insert($calendarListEntry);
printf('Event created: %s\n', $event->htmlLink);
This code returns the error "You need to have writer access to this calendar.", and in the actual Google Calendar sharing screen, I cannot give the service account further privileges.
I've also tried the Google Calendar API Quickstart, but I don't want it to be run off the command line. Also, I don't need access to edit the individual user's calendar, I just want to have my code add an event to my calendar. What's the most efficient way to do this?