繁体   English   中英

如何使用Google API JavaScript获取多个网站供稿

[英]How to get multiple website feed using google api javascript

此功能不采用这两个网站供稿,仅采用第一个网址

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);
}

答案很简单,您需要2个feed对象,因为Feed的构造函数需要一个简单的url。 试试看:

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);
}

它为我工作。 我只需要将Google的代码与上述答案合并即可。

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM