Google Calendar

The Google Calendar API lets you develop client applications that create new events, edit or delete existing events, and search for events. To access calendar services you need to grab an access token by authenticating first. The calendar scope when generating a URL can be passed by simply setting 'calendar' to getLoginURL(). Figure 1 shows how we can obtain an access token for Google Calendar.

Figure 1. Authentication

$auth = eden('google')->auth('[CLIENT_ID]', '[CLIENT_SECRET]', '', '[API_KEY]');

//if no code and no session
if(!isset($_GET['code']) && !isset($_SESSION['token'])) {
    //redirect to login
    $login = $auth->getLoginUrl('calendar');
    header('Location: '.$login);

//Code is returned back from google
if(isset($_GET['code'])) {
    //save it to session
	$access = $auth->getAccess($_GET['code']);
    $_SESSION['token'] = $access['access_token'];

When we have our token we can then access the different service levels of Google Calendar.

Figure 2. Instantiate Calendar
$calendar = eden('google')->calendar($_SESSION['token']);
Figure 3. Calendar Methods
Method Arguments Returns Description
$calendar->acl(); none Eden_Google_Calendar_acl Returns Google acl
$calendar->calendars(); none Eden_Google_Calendar_Calendars Returns Google Calendars
$calendar->getColors(); none array Returns the color definitions for calendars and events.
$calendar->event(); none Eden_Google_Calendar_Event Returns Google Event
$calendar->freebusy(); none Eden_Google_Calendar_freebusy Returns Google freebusy
$calendar->lists(); none Eden_Google_Calendar_List Returns Google List
$calendar->settings(); none Eden_Google_Calendar_Settings Returns Google setting

© 2012 Openovate Labs. All rights reserved.