gpt4 book ai didi

rss - 阻止 Google Feed API 使用缓存的 Feed

转载 作者:行者123 更新时间:2023-12-02 04:18:57 27 4
gpt4 key购买 nike

我正在使用Google Feed JSAPI读取/解析提要。问题是,当提要更改时,之前的条目将变得无效(链接和图像不起作用),因此我无法加载提要的缓存版本。我认为加载提要时会有一个选项不使用缓存版本,但我没有看到。我的解决方案是在 feed url 的末尾添加一个变量 (t),这样它是“唯一的”,但这看起来很奇怪(但它有效)。有人知道更好的方法吗?

    function onLoad() {
// Create a feed instance that will grab feed feed.
var feed = new google.feeds.Feed(feedLocation+"&t="+new Date().getTime());

// Request the results in XML (so that we can parse out all the info
feed.setResultFormat(google.feeds.Feed.XML_FORMAT);

//must set this - if you don't, it defaults to 4
feed.setNumEntries(50);

// Calling load sends the request off. It requires a callback function.
feed.load(feedLoaded);
}

最佳答案

这个答案可能会迟到,但我看到了这篇文章并使用 pxpgraphics 评论得到了解决方案。对于那些需要使缓存失效的人来说,这样做就可以了。请注意,此代码示例是从 RSS 提要中提取其他数据;根据您的需要进行修改。

google.load("feeds", "1");

function initialize() {
var feedLocation = "http://feeds.bbci.co.uk/news/rss.xml";

/* Use the randomNum and the time to invalidate the Google cache and
fetch the latest articles.
*/
var randomNum = Math.floor((Math.random() * 10000) + 1);
var url = feedLocation + "?&t=" + new Date().getTime() + randomNum;

var feed = new google.feeds.Feed(url);
feed.setNumEntries(1000);
feed.load(function(result) {
if (!result.error) {
var container = document.getElementById("feed");
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var div = document.createElement("div");
div.appendChild(document.createTextNode(entry.title));
div.innerHTML += "<br>" + entry.publishedDate;
div.innerHTML += "<br>" + entry.content;
container.appendChild(div);
}
}
});
}
google.setOnLoadCallback(initialize);

此代码假设页面上有此DIV:

<div id="feed"></div>

关于rss - 阻止 Google Feed API 使用缓存的 Feed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13401936/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com