This article is more than 1 year old

Retrieving RSS/Atom Feeds with the Google AJAX Feed API

Using feeds to manage online news.

For JSON result format the <feed> element has the sub-elements described in the following table:

Sub-Element Description
title Specifies the feed title.
link Specifies the URL of the HTML version of the feed.
description Specifies the feed description.
author Specifies the feed author.
entries[] One or more entries may be present. Each entry has the following sub-elements: title-The entry title.link-URL of the HTML version of the entry.content- Specifies content of the entry including HTML tags. contentSnippet-A snippet version of the content. publishedDate-Date of publication.categories[]-One or more category String tags.

For google.feeds.Feed.MIXED_FORMAT result format, both the feed and xmlDocument sub-elements are present in the root element. An additional sub-element called xmlNode is present for each entry for MIXED_FORMAT. The xmlNode sub-element is a pointer to the XML element in the XML document in the xmlElement element.

The google.feeds.FeedControl class is used to download and display multiple feeds. The FeedControl methods are described in the following table:

Method Description
addFeed(url, label) Adds the feed specified by the url to the FeedControl.
draw(element, opt_options?) Loads the feeds and displays the feeds. The element argument specifies the DOM node that contains the resulting entries. The optional opt_options specifies the control options as a JSON object to display the results. The object has a single property called drawMode, which has the value google.feeds.FeedControl.DRAW_MODE_TABBED or google.feeds.FeedControl.DRAW_MODE_LINEAR (default).
setNumEntries(num) Specifies the number of entries for each feed. Default value is 4.
setLinkTarget(linkTarget) Specifies the link target to display the HTML for an entry. The following values may be specified:google.feeds.LINK_TARGET_BLANK google.feeds.LINK_TARGET_SELF (default)google.feeds.LINK_TARGET_TOP google.feeds.LINK_TARGET_PARENT

The Google Ajax Feed API provides a global method google.feeds.getElementsByTagNameNS(node, ns, localName), which returns a NodeList of elements of the specified local name and namespace URI.

Preliminary Setup

We want to develop a JavaScript application to download and display RSS/Atom feeds with the Google Ajax API. First, we need to register a web application URL with the Google AJAX Feed API to download and display Atom feeds.

We shall create the JavaScript application in JDeveloper. Download and install JDeveloper 10.1.3.2. To create a JDeveloper application select File>New and subsequently select General>Application in the New Gallery Click on OK. Specify an Application Name and click on OK. Specify a Project Name and click on OK. A new application and project are added to the Applications-Navigator.

Add a HTML page to the JDeveloper project by selecting the project node and selecting File>New and subsequently selecting Web Tier>HTML>HTML Page. An HTML page is added as shown in Figure 1.

Shows the JDeveloper Application.

We need to register the URL for the HTML page with the Google Ajax Feed API. Right-click on the HTML page and select Run. Obtain the URL, which is http://142.179.34.223:8990/GoogleRSS-GoogleRSS-context-root. Sign up for the Google AJAX Feed API using the URL http://code.google.com/apis/ajaxfeeds/signup.html as shown in Figure 2. Click on the Generate API Key button to generate the API key (you’ll need to be logged in to your Google user account to generate this).

Shows the generation of a Google Feed API key

More about

TIP US OFF

Send us news


Other stories you might like