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);

Comments
Thank you very much, you saved me from pulling out my hair.
Posted by: Garry Benfold
On September 20, 2008 4:33 PM
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...
Posted by: Rhett
On October 27, 2008 1:49 PM
What if for some reason your feed doesn't have a xml tag. Has that happened to you?
Posted by: Remi
On February 13, 2009 10:54 AM
I meant: "What if for some reason your feed doesn't have a gd:when xml tag?"
Posted by: Remi
On February 13, 2009 11:52 AM
Thanks!!!
Posted by: Bill Fulton
On March 30, 2009 11:41 AM
You are the man! Thank you for posting this.
Posted by: Dave
On July 28, 2009 12:10 PM
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.
Posted by: Andy
On October 15, 2009 10:18 AM
Yes... that is what I show you how to do above. Doesn't that work?
Posted by: Kamran
On October 15, 2009 11:35 AM