function _agenda_load_google in Agenda 6.2
Same name and namespace in other branches
- 7.2 agenda.module \_agenda_load_google()
Fetch the gData feed and parse the XML
TODO: Update this docblock.
@access private
Parameters
string $googleid The calendars Google ID:
object $block The agenda block settings:
Return value
object An object containing the status, request and result
2 calls to _agenda_load_google()
- agenda_debug in ./
agenda.admin.php - Provide a page to debug a calendar ID that is not working
- agenda_get_events in ./
agenda.module - Given a list of calendar IDs, parse out and return any event data
File
- ./
agenda.module, line 466
Code
function _agenda_load_google($address, $key, $block) {
$calendar_id = $address;
$googlekey = !empty($block->googleapi_override) ? $block->googleapi_override : variable_get('agenda_googleapi', '');
//Including the google-api-php-client library (required).
$autoload_path = libraries_get_path('google-api-php-client') . '/autoload.php';
if (!file_exists($autoload_path)) {
drupal_set_message('Agenda: The google-api-php-client library was not found.', 'error');
return;
}
include_once $autoload_path;
// https://developers.google.com/google-apps/calendar/v3/reference
$client = new Google_Client();
$client
->setApplicationName('agenda_events_feed');
$client
->setDeveloperKey($googlekey);
$service = new Google_Service_Calendar($client);
$optParams = array(
'orderBy' => 'startTime',
'singleEvents' => 'true',
'timeMin' => date('Y-m-d', strtotime($block->start)) . 'T00:00:00' . date('P'),
'timeMax' => date('Y-m-d', strtotime($block->end)) . 'T00:00:00' . date('P'),
'maxResults' => $block->maxevents,
'timeZone' => $block->timezone,
);
try {
$events = $service->events
->listEvents($calendar_id, $optParams);
} catch (Exception $e) {
drupal_set_message(t('Agenda: Bad call to list events. Check Google API Key or Calendar Address.'), 'error');
drupal_set_message('<pre>' . $e . '</pre>', 'error');
return;
}
return $events;
}