如何使用google api javascript获取多个网站提要
此函数不获取这两个网站提要,只获取第一个url如何使用google api javascript获取多个网站提要,javascript,rss,Javascript,Rss,此函数不获取这两个网站提要,只获取第一个url 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.includeHis
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个提要对象,因为提要的构造函数采用一个简单的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);
}
这对我有用。我只需要将谷歌的代码与上面的答案合并
<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>
加载(“提要”,“1”);
函数loadFeed(url)//用于多个url
{
var feed=new google.feeds.feed(url);//用于多个url
feed.includeHistoricalEntries();//包含旧内容
feed.setNumEntries(15);//条目数
feed.load(函数(结果){
如果(!result.error)
{
result.feed.entries.forEach(函数(条目)
{
var findImg=entry.content;
var img=$(findImg.find('img').eq(0.attr('src');//我使用jquery查找第一个img src
$(“#提要”).append('your html here');
});
}
});
}
setOnLoadCallback(函数OnLoad(){
["http://firstURL.com/category/categoryname/feed/", "http://secondURL.com/category/categoryname/feed/, http://thirdURL.com/category/categoryname/feed/“].map(loadFeed);
});