I'm trying to find out how to integrate the Google calendar using the v3 API with an existing application for a local non-profit organization.
The intent is the following: our organisation has a general public Google calendar (with Google account) that both visitors and active volunteers can subscribe to or show in their own calendar. We are in the process of developing a simple management web application (written in PHP) in which task forces can be created and managed. The core functionality is planning meetings (and managing the notes of these meetings, but this is not relevant to the question.). Users are notified via e-mail when a meeting is planned. It would also be very nice if the planned meetings could be programmatically added to the Google calendar. I now have to do this manually for every planned meeting.
I've been reading the documentation over at developers.google.com and the Google Code page for the php library for two days now and I find myself lost in different authentication schemes, account types, keys and many more, to the point where I'm starting to think that this is not an intended use case.
To come to the core of my question: I need to access the organisations Google calendar, and be able to post events, without any human interaction. Is this even possible? If so, Which account do i need to create (web app, service account or installed app?) in the Google APIs console? How would I authenticate the application? Do I need to grant rights to the application somehow? Is there an example somewhere I can refer to (possibly with a different API?)?
From what I've seen, the critical difference with all examples in Google's documentation, is that I do not want to modify a current or end-user's calendar, but the same calendar, regardless of the logged in user. (user authentication does not happen with the Google api, we rolled our own.) The redirect/user consent mechanism isn't exactly useful for me.
In this question, the asker is trying to achieve something similar. The full answer is not provided however. I can't seem to find some of the sources referred to in the accepted response.
You should be able to make a start with the sample code from here: https://code.google.com/p/google-api-php-client/source/browse/trunk/examples/calendar/simple.php
And referring to here: https://developers.google.com/google-apps/calendar/v3/reference/events/quickAdd#examples
Regarding authentication, you'll need to visit https://code.google.com/apis/console?api=calendar to create and obtain the relevant keys, but it's not very clear so you might need to play around a bit.
I created a "service account" for API access, which gave me the client ID and let me download a private key, but I'm not sure without trying things further how that applies to the code sample linked above.
EDIT
I just found some old code that still works which creates events in calendars using the ZendGdata-1.10.2 library:
//for Google Calendar
set_include_path('./ZendGdata-1.10.2/library');
function createAlert($message, $date) {
$google = array();
// Define credentials for the Google Calendar account
$google['GCAL_USER'] = "info@example.com";
$google['GCAL_PASS'] = "password123";
// Include Zend GData client library
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
// Get Google Calendar service name (predefined service name for calendar)
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
// Authenticate with Google Calendar
$client = Zend_Gdata_ClientLogin::getHttpClient($google['GCAL_USER'], $google['GCAL_PASS'], $service);
date_default_timezone_set('GMT');
// Create a calendar object
$calendar = new Zend_Gdata_Calendar($client);
// Create a new event
$event = $calendar->newEventEntry();
$event->title = $calendar->newTitle($message);
// Add our message as the event content
$event->content = $calendar->newContent($message);
$when = $calendar->newWhen();
// Min time is 5 mins away
if ($date == "" || strtotime('+5 minute') >= strtotime($date)+300) {
$when->startTime = date("c", strtotime('+5 minute'));
$when->endTime = date("c", strtotime('+10 minute'));
} else {
$when->startTime = date("c", strtotime($date)+300);
$when->endTime = date("c", strtotime($date)+600);
}
$event->when = array($when);
// Setup reminders for event
$reminder = $calendar->newReminder();
$reminder->method = "all";
$when = $event->when[0];
$when->reminders = array($reminder);
// Send the new event to be added to Google Calendar
if (defined('GCAL_ID')) {
$newEvent = $calendar->insertEvent($event, 'http://www.google.com/calendar/feeds/' . $google['GCAL_ID'] . '/private/full');
} else {
$newEvent = $calendar->insertEvent($event);
}
// Check response
if (stripos($newEvent->id->text, "http://www.google.com/calendar/feeds/". str_replace('@', '%40', $google['GCAL_ID']) ."/private/full/") !== false) {
return "Sent!
";
} else {
return $newEvent->id->text;
}
}