Parsing RSS Feeds with Google Feed API

The RSS Search Engine and the Social Sharing Analytics tool use the Google Feed API to fetch and parse RSS Feeds.

Here’s how Google Feed API can be used to fetch any RSS Feeds – it can load a maximum of 20 entries per feed.


// Load the Google JavaScript API
<script type="text/javascript" src="http://www.google.com/jsapi"></script>

<script type="text/javascript">

// Load the Google Feeds API
google.load("feeds", "1");

// Parse the query parameters in the REQUEST URL
function qs(search_for) {
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i = 0; i < parms.length; i++) {
        var pos = parms[i].indexOf('=');
        if (pos > 0 && search_for == parms[i].substring(0, pos)) {
            return parms[i].substring(pos + 1);
        }
    }
    return "http://feeds.labnol.org/labnol";
}

// The RSS feed is in the "q" variable of the Query String
function initialize() {

    var rss = qs("q") 
    var feed = new google.feeds.Feed(rss);

    // Maximum number of allowed entries is 20
    feed.setNumEntries(20);

    feed.load(function (result) {
        if (!result.error) {
            for (var i = 0; i < result.feed.entries.length; i++) {
              console.log ("Title: " + entry.title);
              console.log ("URL: "   + entry.link);
              console.log ("Date: "  + entry.publishedDate);
              console.log ("HTML: "  + entry.content);
            }
        } else 
              console.log("Google Feed API could not find the RSS Feed"); 
    });
 }
 google.setOnLoadCallback(initialize);
&lt;/script&gt;