0

I'm using this code to add an Event to my Calendar :

<?php
set_include_path( get_include_path() . PATH_SEPARATOR . 'lib/google-api-php-client-master/src' );
require_once 'lib/google-api-php-client-master/src/Google/Client.php';
require_once 'lib/google-api-php-client-master/src/Google/Service/Calendar.php';
$client = new Google_Client();
$client->setApplicationName("Calendar");
$scopes = array('https://www.googleapis.com/auth/prediction', 'https://www.googleapis.com/auth/calendar');
$service_account_name='xxxx@developer.gserviceaccount.com';
$key_file_location='lib/myKey.p12';
$key = file_get_contents($key_file_location);
$auth_credentials = new Google_Auth_AssertionCredentials($service_account_name, $scopes, $key);
$client->setAssertionCredentials($auth_credentials);
$client->setClientId('xxxx.apps.googleusercontent.com');
$service = new Google_Service_Calendar($client);

try { 

$event = new Google_Service_Calendar_Event();
$event->setSummary('Halloween');
$event->setLocation('The Neighbourhood');
$event->setDescription('rien');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2014-04-02T10:00:00.000-07:00');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2014-04-03T10:25:00.000-07:00');
$event->setEnd($end);




$createdEvent = $service->events->insert('primary', $event);

echo $createdEvent->getId();
}
catch (Exception $ex)
{
    die($ex->getMessage());
}
?>

I get the Event ID, it is printed out, but when I look at my calendar in a browser - there is absolutely nothing.

1 Answers1

0

It's creating the event in the service account's calendar, check my answer here.

Community
  • 1
  • 1
Vinicius Braz Pinto
  • 8,209
  • 3
  • 42
  • 60