Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rss 阻止Google提要API使用缓存提要_Rss_Google Api_Google Feed Api - Fatal编程技术网

Rss 阻止Google提要API使用缓存提要

Rss 阻止Google提要API使用缓存提要,rss,google-api,google-feed-api,Rss,Google Api,Google Feed Api,我正在使用读取/解析提要。问题是,当提要更改时,以前的条目变得无效(链接和图像不起作用),因此我无法加载提要的缓存版本。我认为在加载提要时可以选择不使用缓存版本,但我没有看到。我的解决方案是在feedurl的末尾添加一个变量(t),这样它就“唯一”了,但这似乎有点骇人听闻(但它是有效的)。有人知道更好的方法吗 function onLoad() { // Create a feed instance that will grab feed feed. var fe

我正在使用读取/解析提要。问题是,当提要更改时,以前的条目变得无效(链接和图像不起作用),因此我无法加载提要的缓存版本。我认为在加载提要时可以选择不使用缓存版本,但我没有看到。我的解决方案是在feedurl的末尾添加一个变量(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);
    }

尝试
feed.includeHistoricalEntries()
它可能会解决你的问题。

这个答案可能会来得很晚,但我偶然发现了这篇文章,并通过
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);

(顺便说一句,让Vogon诗集继续运行!)从API文档中可以看出,这听起来并不能满足我的需要。事实上,听起来我想不包括历史事件()。我试试看。回复:Vogon诗歌-我会的!:)是我的博客:)哦,好的,对不起。因此,您希望使缓存“无效”。也许是用一个随机参数询问URL?这正是我说的我现在正在做的:“我的解决方案是在提要URL的末尾添加一个变量,这样它是“唯一的”,但这似乎有问题(但它是有效的)”,但我在找一些不那么有问题的东西:)这个随机参数也可以是一个随机数
var randomNum=Math.floor((Math.random()*10000)+1)
var url=feedLocation+“&t=“+new Date().getTime()+randomNum您找到解决方案了吗?这里的问题是,提供提要的服务器正在使用基于提要URL的缓存。因此,如果我在URL的查询字符串中添加一个随机字符串,那么这不仅会绕过Google的缓存,还会绕过服务器的缓存。我想我必须修改服务器来添加一个特殊的旁路外部缓存参数,在进行内部缓存时会被忽略。不,除了我在问题中提到的,没有其他解决方案-将时间作为“随机”参数添加。它可以工作,只是没有我想要的那么干净。我现在也在做同样的事情,添加了类似:
“?bypass_cache='+Math.floor(Date.now()/refreshIntervalInMs)
啊-这不是一个坏的解决方案-至少它确实缓存了它,但它是以一种由refershIntervalInMs控制的方式缓存的。仍然是一个黑客,但比我的更优雅,它从不使用缓存。这是可行的,但并不比我用“new Date().getTime()”做的更好。我希望有一些更优雅的东西,不需要附加一个“随机”参数,并且实际使用了缓存。到目前为止,@feklee提出的使用refreshIntervalInMs的解决方案最接近我想要的。你说得对。我希望有一个内置的方式告诉谷歌不要缓存它。也许他们更喜欢这种方式,因为这可能会减少服务器的工作量。
<div id="feed"></div>