Some time ago I reworked my home page to feature content from various other sites I post to (blogs, flickr, delicious) by using some JSON tricks to pull in their feeds. I blogged about how to do this with Feedburner’s JSON API, so that my actual page was just static HTML and all the work was done client-side.
Last week I decided to revisit this using Google’s new AJAX feeds API. Feedburner’s API never seemed to be well supported (it came out of a hackathon) and it forced me to serialize my requests. In the process I neatened up a bunch of the code.
Google’s API is pretty straight-forward. It uses a loader model that is similar to Dojo’s dojo.require, so you load the main Google library:
<script src="http://www.google.com/jsapi?key=YOURAPIKEY" type="text/javascript"></script>
and then ask it to load their feed library:
google.load('feeds', '1');
They have a handy way of setting a callback to be called when the libraries are loaded:
google.setOnLoadCallback(function () { /* just add code */ });
By putting all three of these together we have a straight-forward way to execute code at the right time.
I refactored the code that inserts the feed data into the page a lot. I fleshed out the concept of input filters from simply filtering the title to filtering the whole item objects. This allows for a more flexible transformation from the information that is presented in the RSS feeds to information that I want to present to visitors to my page. In practice I only used it to remove my name from Twitter updates. Instead of hard-coding the DOM node creation like I did in the previous version of the code I moved to a theme model. The theme function takes a feed entry and returns a DOM node to append to the target DOM node.
The flexibility of Google’s API let me abandon my separate code path for displaying my Flickr images. Previously I used Flickr’s own JSON feed API but since Google’s feed API supports returning RSS extensions I used the Flickr’s MediaRSS compliant feeds to show thumbnails and links. They even provide a handy cross-browser implementation of getElementsByTagNameNS (google.feeds.getElementsByTagNameNS) for us to use.
I’m tempted to write a client-side implementation of Jeremy Keith’s lifestream thing using this API.
Take a look at the code running on my home page or check out the script.


2 Comments
Google apps hello:
first, sorry for my english, i speak spanish…
second, i found your website googling by your nickname in drupal.org and want ask you about somethinng…
in drupal.org you write about a drupal module that “to allow authenticating a drupal site against a free google-apps-for-your-domain (or the gmail domain) for an older version of Drupal. and I’ve been meaning to finish it and update it for Drupal 5. If there’s interest I’ll raise its priority” and i want to now if you finished o planed to do it, because i’m interest in thant project for my website…
if you need help, i’ll help where ever you need to complete that module…
well, that’s it…
i’m sorry if you feel that i’m been (freco, patuo, no se como se escribe en ingles, pero quiero decir que te pase a llevar dejandote un mensaje aqui)…
i hope that you are ok…
i’ll hoping your answer…
thank you
byte
Re: Google apps I never quite got around to this. I don’t think I actually need to write it anymore, and it never quite worked right.
The Google Authentication APIs are fairly straight-forward though – I had the most trouble getting Drupal to play nice.
Ian