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
Very useful. Thanks! Looking at the reference link that you provided, I also like adding singleevents=true, which expands recurring events into multiple individual ones
Posted by: Facundo
On November 30, 2009 12:59 PM
Hi!
I'm wondering where I should place this code: $feed->enable_order_by_date(false);
It doesn't appear to be working if I nest it inside of the code you provided above. Any help would be greatly appreciated!
Posted by: Matt
On December 4, 2009 5:50 PM
@Matt, do you use SimplePie? if you do then it should work by adding it anywhere but preferably at the top of the script before the parsing. However, if you don't use SimplePie then you dont have to worry about that part.
Posted by: Visuex
On December 11, 2009 2:02 AM
i use wordpress.com and found this INCREDIBLY useful.
i do have a question however, is there a way to get it to not show events that have passed? (ie: start with any event that occurs from today onward)
Posted by: franky vivid
On January 1, 2010 4:15 PM
hey kids! i nailed it. i answered my own question and figured i'd share it with you.
if you only want to show future events, well you add:
futureevents=true
that simple.
Posted by: franky vivid
On January 1, 2010 4:23 PM
Hi. I'm displaying the Google Calendar RSS feed through the SimplyRSS plugin code on a Wordpress website. It will only display the date "1970/01/01" and not the event date. I understand that's some sort of default date, but I'm not sure why it's not working. Any thoughts would be much appreciated.
Posted by: Alan
On January 7, 2010 6:10 PM
Additional Info: The events are displaying properly otherwise, and they are sorting properly from soonest to latest. Thanks!
Posted by: Alan
On January 7, 2010 6:12 PM
Thanks so much for posting this. Really helpful!
Posted by: Nancy Schorr
On January 21, 2010 6:56 PM
Awesome! This is what I have been trying to do for a few days now. Thanks!
Posted by: Dan
On January 24, 2010 9:41 PM
hi, thanks for your informations. but i would like to filter the feed. i would like to show only the daily events. how can i do it? thanks
Posted by: bgenymous
On January 30, 2010 10:14 AM
I have a problem with my feed. i check the whol code and nothing. If any body help me... :(
Posted by: Betsi
On February 1, 2010 11:16 PM