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?

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

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!

@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.

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)

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.

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.

Additional Info: The events are displaying properly otherwise, and they are sorting properly from soonest to latest. Thanks!

Thanks so much for posting this. Really helpful!

Awesome! This is what I have been trying to do for a few days now. Thanks!

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

I have a problem with my feed. i check the whol code and nothing. If any body help me... :(

Post a comment

About the Author

Kamran
Divide by Zero is Kamran Ayub's personal blog. Kamran owns and operates Intrepid Studios, a web design and development firm based in Minneapolis. Despite the above picture, Kamran is usually an intelligent person. Please forgive him.

View Kamran Ayub's profile on LinkedIn

Add to Technorati Favorites


Powered by
Movable Type 4.25