Aman Yadav
Aman Yadav

Reputation: 39

How to get multiple website feed using google api javascript

This function is not taking these two website feeds, Only first url is taken

function OnLoad() {
  // Create a feed instance that will grab Digg's feed.
  var feed = new google.feeds.Feed("http://www.tricks10.com/feed","http://liveurlifehere.com/blog/feed/");
  feed.setNumEntries(25);
  feed.includeHistoricalEntries();
  // Calling load sends the request off.  It requires a callback function.
  feed.load(feedLoaded);
}

Upvotes: 1

Views: 290

Answers (2)

Nate McConnell
Nate McConnell

Reputation: 325

It worked for me. I only had to merge google's code with the answer above.

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
            <script type="text/javascript">
                google.load("feeds", "1");
                function loadFeed(url) //for multiple urls
                   {
                    var feed = new google.feeds.Feed(url); //for multiple urls
                    feed.includeHistoricalEntries(); //include old stuff
                    feed.setNumEntries(15); //number of entries
                    feed.load(function (result) {
                        if (!result.error) 
                        {
                            result.feed.entries.forEach(function(entry)
                            {
                                var findImg = entry.content;
                                var img = $(findImg).find('img').eq(0).attr('src'); //i use jquery to find 1st img src
                                $('#feed').append('<div>your html here</div>');

                            });
                        }

                    });

                }
                google.setOnLoadCallback( function OnLoad() {
                ["http://firstURL.com/category/categoryname/feed/", "http://secondURL.com/category/categoryname/feed/, http://thirdURL.com/category/categoryname/feed/"].map(loadFeed);
                });

    </script>

Upvotes: 0

Julien Genestoux
Julien Genestoux

Reputation: 32972

The answer is simple, you need 2 feed objects because the constructor for a Feed takes a simple url. Try that:

function loadFeed(url) {
  var feed = new google.feeds.Feed(url);
  feed.setNumEntries(25);
  feed.includeHistoricalEntries();
  feed.load(feedLoaded);
}

function OnLoad() {
  ["http://www.tricks10.com/feed", "http://liveurlifehere.com/blog/feed/"].map(loadFeed);
}

Upvotes: 1

Related Questions