1
我使用google feed api进行实验。基本上,我需要一个我的提要列表以及提要条目的一些信息,以便处理通常在谷歌阅读器上不可用的历史提要。我对谷歌饲料API的一种行为感到困惑,我在下面的代码中将其记录为注释。因为我是js的新手,所以我确定我没有得到任何东西。Google feed api behavior
这是我的问题的代码注释:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" charset="UTF-8" >
google.load("feeds", "1");
/* Here I define the list of my feeds */
var feeds=['MYFEED1', 'MYFEED2', 'AND SO ON'];
function initialize() {
for (var j=0;j<feeds.length;j++) {
var feed = new google.feeds.Feed(feeds[j]);
feed.includeHistoricalEntries();
feed.setNumEntries(100);
feed.load(function(result) {
if (!result.error) {
var container = document.getElementById("out");
var furl = result.feed.feedUrl;
var flink = result.feed.link;
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var div = document.createElement("div");
/* HERE IS WHERE I DON'T GET IT.
feeds[j] always just shows the last feed in the array.
But furl always shows the correct feedUrl
Though if I uncomment alert("NEXT") few lines below
thus giving a short pause, feeds[j] correctly
shows the same url as feedUrl. Why? */
div.appendChild(document.createTextNode(feeds[j]+" "
+furl+" "+flink+" "+ entry.link + " " + entry.title));
container.appendChild(div);
}
}
});
//alert("NEXT");
}
}
google.setOnLoadCallback(initialize);
</script>
</head>
<body><div id="out" ></div>
</body>
</html>
此外,我想知道是否有通过查询mysql数据库设置饲料数组的值的方式。
谢谢哈里什,我想你的建议,将开始和结束的结束,但我没有得到在浏览器上任何东西。只是空白。 – Gius
@Gius - 我不熟悉谷歌饲料api,但当我尝试!result.error总是评估为false,因此如果块内部的代码永远不会执行,因此空白页面。错误对象具有无效的url错误(代码400)。 – Harish
但没有关闭,这个错误没有发生,谢谢。不是什么大不了的事情,我只是感到困惑,但我认为我理解你说的理由是异步 – Gius