I'm trying to add an event to a Google calendar directly from a php script but am getting this error:
Fatal error: Call to a member function insert() on a non-object...
<?php
set_include_path("scripts/google-api-php-client/src/" . PATH_SEPARATOR . get_include_path());
$path = $_SERVER['DOCUMENT_ROOT'];
$google_client = $path . '/xxxx/scripts/google-api-php-client/src/Google_Client.php';
include ($google_client);
require_once $path . '/xxxx/scripts/google-api-php-client/src/contrib/Google_CalendarService.php';
$event = new Google_Event();
$event->setSummary('Pi Day');
$event->setLocation('Math Classroom');
$start = new Google_EventDateTime();
$start->setDateTime('2013-03-14T10:00:00.000-05:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2013-03-14T10:25:00.000-05:00');
$event->setEnd($end);
// error is on this next line
$createdEvent = $cal->events->insert('some_calendar@gmail.com', $event);
echo $createdEvent->id;
?>
I've seen in many of the examples that I have looked at that some use code similar to this:
$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Event Creator");
$client->setClientId('MY CLIENT ID ADDRESS IS HERE');
$client->setClientSecret('MY CLIENT SECRET KEY IS HERE');
$client->setRedirectUri('http://localhost/phpt/caladd.php');
$client->setDeveloperKey('MY API KEY IS HERE');
$cal = new Google_CalendarService($client);
But this looks to me like there is some application that is being referenced and is what is generating the calendar event. In my case, ideally, I just want my php script to make the calendar entry. There is no other "application" involved.
Do I need to have a Google_Client in order to add a simple entry to a Google Calendar? It seems excessive to me, but maybe that's the only way to do this.
Am I overlooking a step in this process? Or is there a bug in the code as I've written it. Any help is appreciated, including links to examples. Thank you.