This article is more than 1 year old

Retrieving RSS/Atom Feeds with the Google AJAX Feed API

Using feeds to manage online news.

Keeping up to date with updates to different news websites can be a major burden – which can be ameliorated with an RSS feed. With an RSS feed, the updates are pushed to you as they become available.

RSS is a collection of web feed formats, specified in XML and used to provide frequently updated digital content to users. The first version of RSS, RSS 0.9, was created by Netscape in 1999 but the “RSS” acronym has different interpretations for different subsequent standards: for RSS 2.0, Really Simple Syndication; for RSS 0.91 and RSS 1.0, Rich Site Summary; for RSS 0.9 and RSS 1.0, RDF Site Summary.

An RSS feed may be read using a feed reader such as Google Reader or RssReader. It may also be read using a Feed API and Google provides the Google AJAX Feed API to receive any RSS feed.

An RSS Feed may be displayed in JSON Result Format, XML Result Format, or combined JSON/XML Result Format. JSON (JavaScript Object Notation) is a data interchange format used to transmit structured data and is based on the following data structures:

  1. Object-Collection of key-value pairs, separated by a comma, and enclosed in { }.
  2. Array-Ordered sequence of values, separated by a comma and enclosed in [ ].

By default, the Ajax Feed API returns the feed in JSON format.

Because of the incompatibilities between the various versions of RSS and the limitations of RSS, a new syndication specification, Atom, was introduced in 2003. Atom is not a strict superset of RSS - for a comparison between RSS 2.0 and Atom 1.0 see here. An Atom feed has 3 main advantages over the original RSS feed:

  • An RSS feed supports only plain text and HTML, whereas an Atom feed supports various additional content types such as XHTML, XML and binary, and references to video and audio content.
  • Atom is being standardised by the IETF (RFC4287), whereas RSS is not standardised.
  • Atom supports XML standard features such as XML Schema. RSS doesn’t.

We shall use standard Atom feeds in this article. It’s also worth noting that Microsoft has introduced the Simple Sharing Extensions (SSE), which “extend” the Atom 1.0 and RSS 2.0 specifications to provide item sharing between cross-subscribed feeds. However, note that an extended standard is no longer really a standard, although this one appears to be using, rather than re-inventing, the underlying RSS/Atom specs.

Overview of Google Ajax Feed API

The Google Ajax Feed API generates a result document, whose structure is different from either an RSS 2.0 or the Atom 1.0 feed. For example, it may contain elements such as "contentSnippet" and "publishedDate". Neither Atom 1.0 nor RSS 2.0 has these elements. The "contentSnippet" element corresponds to the snippet version of the <content> or <summary> element in Atom 1.0 and <description> element in RSS 2.0. The "publishedDate" element corresponds to the <published> element in Atom and the <pubDate> element in RSS 2.0. The Google Feed API uses its own set of result elements to generate a uniform result format for an Atom 1.0 feed and an RSS 2.0 feed, which each have some elements different. A Google Ajax Feed is represented by the google.feeds.Feed class.

The Feed class methods do not have a return type. The Feed class methods are presented in the following table:

Method Description
load(callbackFunction) Downloads the feed from the Google server. The callbackFunction is invoked when the download is complete. The callbackFunction is invoked with a argument that represents the result of the feed.
setNumEntries(num) Sets the number of feed entries. Default value is 4.
setResultFormat(format) Sets the result format. One of the following values may be specified: google.feeds.Feed.JSON_FORMAT (the default), google.feeds.Feed.XML_FORMAT, or google.feeds.Feed.MIXED_FORMAT.

The root element of the feed result is <root>. If the loading generates an error the root element has an <error> sub-element. The <error> element has sub-elements <code> and <message>. The <code> element specifies the error code and the <message> element specifies the description of the error.

If the result format is JSON_FORMAT or MIXED_FORMAT the <root> element has a sub-element called <feed>. If the result format is XML_FORMAT or MIXED_FORMAT the root element has an element called <xmlDocument> . The xmlDocument element contains the XML document for the feed.

Next page: Preliminary Setup

More about

TIP US OFF

Send us news


Other stories you might like