Designs | Resume | KamranAyub.com | email: ayubx003 (@umn.edu)

« Alright, I Bit the Bullet [Ouch] | Main | New Design: Homecoming 2008 [UMN] »

Customize Google Calendar RSS Feeds: Sort Events, Limit Results, etc. [Tips & Tricks] | Posted at 2:21 PM

If you use an RSS reader to subscribe to people’s Google Calendar events, or you use an RSS parser to read your calendar’s feed onto a webpage, you may have realized that there’s not really any good documentation about customizing that feed. Well, actually, there IS but it’s not apparent from doing a simple Google search that you can use the Google Calendar API reference to see how to customize a feed display.

Today I wanted to do a couple things, I wanted to sort the RSS by start date and from the event happening soonest to the event happening later. I also wanted to limit the results to 5 to reduce time for parsing.

Here’s how to do it, it’s quite simple:

https://www.google.com/calendar/feeds/[account]/public/basic?orderby=starttime&sortorder=ascending&max-results=5

If you notice, all I did was add some query string values.

orderby: starttime – Order results by when they start
sortorder: ascending – Order from least to greatest (soonest to latest)
max-results: 5 – Limit results to 5 events

You can use the following query string keys to customize your RSS data: Google Calendar API Reference

Tip: If you’re using PHP and SimplePie to parse the RSS, you need to add the following line of code to prevent SimplePie from automatically sorting the items by date:

$feed->enable_order_by_date(false);
Filed Under: How To Tips and Tricks

Comments

Thank you very much, you saved me from pulling out my hair.

I'm using SimplePie to display a Google calendar RSS feed. All is well except the time is set to GMT, and I need it to be local. I'm not a programmer, so a basic explanation would by much appreciated...

What if for some reason your feed doesn't have a xml tag. Has that happened to you?

I meant: "What if for some reason your feed doesn't have a gd:when xml tag?"

Thanks!!!

You are the man! Thank you for posting this.

Is there a way to list "the next 5 events in order of start time, STARTING FROM TODAY"?

e.g. something suitable for putting on a RSS feed on My Yahoo or something -- i.e. upcoming events.

Yes... that is what I show you how to do above. Doesn't that work?

Post a comment