Harry Potter and Laura Bush “Facebook needs to be more personal”
Jul 17

Forget the Feed URL

Ajax, Google, JavaScript, Tech Add comments

Having to type in feed URLs, or grep them from view source (as you don’t use the browser specific system) can be a pain.

The Google AJAX APIs team has created a simple way to find feeds, and to locate feeds in a URL.

findFeeds will do a Google search and return entries and feeds related to the search.

Here is an example at work:

findfeeds.png

The code you will write will look like this:

google.feeds.findFeeds(query, function(result) {
var el = document.getElementById("feedControl");

if (result.error || result.entries.length <= 0) {
el.innerHTML = 'No Results Found';
return;
}

// create a feed control
var feedControl = new google.feeds.FeedControl();

// Grab top 4..
for (var i = 0; i < 4; i++) {
feedControl.addFeed(result.entries[i].url, result.entries[i].title);
}

feedControl.setLinkTarget(google.feeds.LINK_TARGET_BLANK);
feedControl.setNumEntries(2);
feedControl.draw(el);
}

lookupFeed takes a URL and returns the feed. E.g.

function newSlideShow(user) {
showStatus('Resolving feed for ' + user);
var url = 'http://www.flickr.com/photos/' + user;
google.feeds.lookupFeed(url, lookupDone);
}

function lookupDone(result) {
if (result.error || result.url == null) {
showStatus('Could not locate feed for user');
return;
}

showStatus('Found Photo Feed');
// We need to switch over from Atom to RSS to get Yahoo Media for slideshow..
var url = result.url.replace('format=atom', 'format=rss_200');
showSlideShow(url);
}

Very nice indeed.

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: Type in the word 'ajax'