>> GreenByte.info By Nick Tong (quiksilv) | Supported by: TalkWebSolutions.co.uk

Using Google Reader and RSS.cfc to aggregate feeds

I'm not sure how others aggregate blog/news feeds etc but I've found an easy (and somewhat simple) way to aggregate feeds using Google reader and Ray Camdens rss.cfc.

All you do is create an account with Google reader and then start adding the feeds you want to aggregate. Add your tags to the feeds i.e. cfEclipse, FuseBox etc and make your feed public. The public feed that you create here will be what we need to grab the data in Ray rss.cfc.

Once you're happy with all your feeds in Google create a page called feeds.cfm - make sure that rss.cfc is in the same folder as this page [or invoke the cfc some other way (recommended)].

Then use this code in feeds.cfm

<cfset myRssFeed = "YourGoogleFeedURL" />
<cfhttp method="get" url="#myRssFeed#" />
<cfset rssObj = createObject("component", "rss");
<cfset request.feed = rssObj.getEntries(cfhttp.FileContent) />

<h1>My Feed</h1>
<cfoutput query="request.feed">
   <h2><a href="#request.feed.link#" title="#request.feed.title#">#request.feed.title#</a></h2>
   <cfif len(request.feed.description)>
      <p>#request.feed.description#</p>
   <cfelse>
      <p>No description available</p>
   </cfif>
</cfoutput>

One thing you will have to do is update line 537 in rss.cfc to this:

<cfif structKeyExists(arguments.xmlData.feed.xmlAttributes,"version")>
         <cfset result.type = "Atom">
         <cfset result.version = arguments.xmlData.feed.xmlAttributes.version>
      <cfelseif structKeyExists(arguments.xmlData.feed.xmlAttributes,"xmlns:gr")>
         <cfset result.type = "Atom">
         <cfset result.version = 2.0>
      </cfif>
This is a bit of a hack but the Google feeds don't have a version number in the returned XML.

Cool huh?

Check out the feed page on cfFrameworks.com to see it in action.


 
Comments
Raymond Camden's Gravatar FYI, I found a bug in rss.cfc when working on my new blog (www.blogarrhea.net). I haven't updated the code yet, but when I do, it will be on RIAForge and you should upgrade. I'll get this before the end of the week.
# Posted By Raymond Camden | 19/10/06 17:50 | Report abusive comment
nick tong's Gravatar Great - i'll watch out for it. I like the look of http://blogarrhea.net
# Posted By nick tong | 19/10/06 18:01 | Report abusive comment
Matt Williams's Gravatar What about the whole New Entry/Mark as read part of Google (or any) reader? Is that just ignored? If you don't go mark them as read would you just output everything, provided you don't add some sort of date filter?

That is one reason I like an RSS Reader vs an aggregator. An aggregator doesn't remember anything about what is new since my last visit.
# Posted By Matt Williams | 20/10/06 13:01 | Report abusive comment
nick tong's Gravatar Hi Matt - you make a good point and one that I think is valid if you intend to involve interaction with your user. This is a very basic example and one that’s proof of concept if nothing else. There are many enhancements that one could do including (to name a few):
archiving data,
search facilities,
remember users viewed posts as you point out.

I do intend to do this so please watch this space.
# Posted By nick tong | 20/10/06 13:20 | Report abusive comment
Hinsel's Gravatar this is a great bit of coding here!
one question: using this code just drops my text into one big block, no line breaks etc as appear in the original blog where it was created. any way to get line breaks in there? have been looking into delimters but nothing has provided any results as of yet...
# Posted By Hinsel | 16/05/08 20:14 | Report abusive comment
BlogCFC was created by Raymond Camden. This blog is running version 5.5.1.