I'm in the process of creating a blog for somebody. They want to pull in a lot of data and integrate it quite tightly into the design, so standard widgets are a no-no. That's been fine until now.
They have a public access Google Calendar with various events on it and I want to grab the next 5 events (from "now" onwards) and display the event title, when that instance of the event starts, its location and a link to the gcal item.
From what I can see, there are three options for grabbing gcal feeds: XML, ical or HTML (containing some really whack JSON). XML seems like the logical choice, right?
Well the XML feed is (after the atom feed description) actually just a lot of faffy HTML. Parsing this is possible but it's a huge pain in the behind because recurring events (of which there are several on the calendar) only show the first instance of that event and (apparently) no information on when the next instance is.
So am I just being a bit dense? Is there a way to show what I want just hacking through the XML API?
Or would I have better luck through iCal? I've never done any iCal with PHP so if you have, please suggest any libs you've used to make things simpler for yourself.
Edit: thanks to the answer, I downloaded the Zend Gdata pack (which, thankfully, is separate to the rest of the Zend Framework). Doing what I need was as easy as this:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_HttpClient');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
$service = new Zend_Gdata_Calendar();
$query = $service->newEventQuery();
$query->setUser('[email protected]');
$query->setVisibility('public');
$query->setProjection('full');
$query->setStartMin(date('Y-n-j'));
$query->setStartMax(date('Y-n-j', time() + (60*60 *24*8)));
$query->setOrderby('starttime');
try { $eventFeed = $service->getCalendarEventFeed($query); }
catch (Zend_Gdata_App_Exception $e) { return; }
foreach ($eventFeed as $event)
echo $event; // do something real here
That should get you a week's worth of events (yes setStartMax is exclusive so setting it 8 days in the future is required).
Hope this helps somebody else in the future.
To retrieve calendar IDs call the calendarList. list method. If you want to access the primary calendar of the currently logged in user, use the " primary " keyword. Event identifier.
All use of the Google Calendar API is available at no additional cost.
The Calendar API lets you integrate your app with Google Calendar, creating new ways for you to engage your users.
Another option is to use the Zend Google Calendar library, it is a separate part of the zend framework so you don't need the whole zend framework
http://framework.zend.com/manual/en/zend.gdata.calendar.html
it is not that hard once you have a look at the examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With