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
I have multiple calendars on my google calendar. Any ideas on how to display this on one feed? Any help would be appreciated!
Posted by: marilee
On February 11, 2010 12:24 PM
To merge google calendars using simplepie:
$feed->set_feed_url(array(
'rss feed url 1',
'rss feed url 2',
'rss feed url 3'
));
Otherwise you can use yahoo pipes to merge the 3 rss urls into 1.
Posted by: me
On April 5, 2010 3:36 PM
thanks, u helped me sort things out...
Posted by: yet another thankful guy
On June 7, 2010 5:02 PM
ok, this is weird.
this feed gives me all future events:
http://www.google.com/calendar/feeds/johnywhy@gmail.com/public/basic?orderby=starttime&sortorder=descending&max-results=5&futureevents=true
but this feed only gives me the next event:
http://www.google.com/calendar/feeds/johnywhy@gmail.com/public/basic?orderby=starttime&sortorder=ascending&max-results=5&futureevents=true
the only difference is the sortorder.
what gives?
thanks
Posted by: johny why
On July 9, 2010 1:44 PM
now it works. maybe takes time for google rss servers to update.
new weirdness, firefox built-in reader reads the sort orders correctly. simplepie reads both feeds in descending order.
Posted by: johny why
On July 9, 2010 10:18 PM
I use RSS alot, so this will help me for sure :)
Posted by: travian scripts
On August 3, 2010 7:59 PM
I can't figure out how to customize the content of the feed. I only want the event title and date, but the feed gives me the location and an 'event status' as well. Any idea?
Posted by: Nikhil
On August 9, 2010 9:12 PM
WHEW!!!!! Thank you! Thank you! Thank you! That was exactly what I needed to know.
Posted by: Selwyn Swe
On August 18, 2010 6:00 PM
This info was amazingly helpful! I was going to ask a dumb question, but decided to follow the link to the Google API. Awesome info! Thank you!!
Posted by: Daddie0
On September 1, 2010 9:13 PM
This is very helpful. I have also noticed Google Calendar's rss includes a lot of unnecessary information. Feedburner at one point had an 'Event Feed' option which gave someone the privileges to edit the content of the feed, but it has since been deactivated. It seems as if this problem has been going on for a while. I would post your questions about the 'Event Status: Confirmed" here. That is a link to google calendars help forum.
Posted by: Simon
On September 10, 2010 1:07 PM
Hi, Thank's for your example, it is fantastic, but I have a problem.
In my google calendar I have 56 events. In rss page I read only 25. Is it correct?
http://www.google.com/calendar/feeds/riccardo.areaphoto@gmail.com/public/basic?orderby=starttime&sortorder=ascending&futureevents=true
Posted by: Riccardo Selvatico
On November 15, 2010 3:21 AM
Thanks for that great information. I used google calendar but not utilizing it like you did.
Posted by: Solar Power System
On December 9, 2010 6:56 PM
Just the info I was looking for. I've fussed with so many wp widgets and just wasn't getting what I wanted, this will let me circumvent all that. Thanks for sharing man. Nice blog name/logo too by the way ;D
Posted by: Kaz
On January 19, 2011 10:38 AM
I have not used Google calender yet but i'm inspired to give this a go - thanks for the info.
Posted by: Slim Drops
On May 24, 2011 2:18 AM
Hi, Confused to buggery here. I put in the link as per above and yet my events are actually listing in the reader in the date and Time order I entered them into the callendar. Is their a substring I can add to force it to see the dates and times of the calendar and not the dreation date and time ?
Posted by: Mario
On September 15, 2011 5:17 AM
Thank you! Thank you! Thank you! That was exactly what I needed to know.
Posted by: Saikrishna
On February 11, 2012 10:56 PM
When I type the rss feed address into internet explorer, it sorts by when the event was edited, not when the event takes place. I have tried adding the orderby=starttime&sortorder=ascending&max-results=5 but it still does not sort. Any ideas on how to fix this?
Also, I do not want to make my calendar public, and it does not give me an html address without making my calendar public.
Posted by: Jessie
On March 14, 2012 10:06 PM
I used this:
?orderby=starttime&sortorder=ascending&max-results=5&futureevents=true
For my first calendar it worked (event did not have start and end time) For second calendar it only put next event (not today's event) even though the time of the event had not yet occurredIt worked for one calendar. Is there a time code or is there a way to say TODAY only and not just future events?
Posted by: David Slentz
On April 18, 2012 8:16 AM
?orderby=starttime&sortorder=ascending&max-results=5&futureevents=true
This shows Today's event only if it does not have a start and end time. Is there a time issue? Or can I choose just TODAY's events only regardless of time?
Posted by: David
On April 18, 2012 8:19 AM
I am using Google calendar for organizing the events for my blog WordPressinas Word. However, we don't know about what are you describe here. So, thank you so much for creating a nice article. It helps me a lot of time.
Best Regards!
Posted by: Mohammad Shadab
On May 5, 2012 1:47 PM