[FIXED] Add Event to Google Calendar


I am adding an event to my calendar using this code

$client = new Google_Client();
$scopes = array('https://www.googleapis.com/auth/prediction', 'https://www.googleapis.com/auth/calendar');

$auth_credentials = new Google_Auth_AssertionCredentials(SERVICE_ACCOUNT_NAME, $scopes, $privateKey);


$cal = new Google_Service_Calendar($client);

 try {
 $event = new Google_Service_Calendar_Event();
 $start = new Google_Service_Calendar_EventDateTime();
 $end = new Google_Service_Calendar_EventDateTime();

 $createdEvent = $cal->events->insert('primary', $event);
 echo $createdEvent->getId()."\n\n";

catch (exception $ex)

I get the event id and it prints, but when I look at the calendar in my browser there is absolutely nothing.

What am I doing wrong?


You need to share your calendar to yourself.

This is for the new Google_Client API.

$scope = new Google_Service_Calendar_AclRuleScope();
$scope->setValue( 'Your Email Goes Here' );

$rule = new Google_Service_Calendar_AclRule();
$rule->setRole( 'owner' );
$rule->setScope( $scope );

$result = $service->acl->insert('primary', $rule);

Reference: Google Calendar API v3 – Not Creating Event (Server-to-Server Authentication)

Answered By – ryanc

Answer Checked By – Gilberto Lyons (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published