Prevent Google Feed API from using cached feed

后端 未结 2 2024
天涯浪人
天涯浪人 2020-12-11 03:13

I am using the Google Feed JSAPI to read/parse a feed. The problem is, when the feed changes, the previous entries become invalid (links and images don\'t work) so I can

相关标签:
2条回答
  • 2020-12-11 03:58

    try feed.includeHistoricalEntries(); It might solve your issue.

    0 讨论(0)
  • 2020-12-11 03:59

    This answer might be coming in late, but I came across this post and got the solution using pxpgraphics comment. For those who need to invalidate the cache, this will do it. Note that this code example is pulling other data from the RSS feed; modify for your needs.

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

    This code assumes you have this DIV on the page:

    <div id="feed"></div>
    
    0 讨论(0)
提交回复
热议问题