使用Google Feed API更改结果数量

时间:2014-02-17 00:18:42

标签: javascript html rss google-api google-feed-api

我正在尝试使用Google Feed API将此网页上显示的项目数量增加到25个而不是4个项目: http://ewh.ieee.org/reg/1/sac/news.php

这是JS:

<script src="//www.google.com/jsapi?key=AIzaSyA5m1Nc8ws2BbmPRwKu5gFradvD_hgq6G0" type="text/javascript"></script>
    <script type="text/javascript">

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

        function feedLoaded(result) {
          if (!result.error) {
            var container = document.getElementById("content");
            container.innerHTML = '';

            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(i + ': ' + entry.title));
              container.appendChild(div);
            }
          }
        }

        function OnLoad() {
          var feedControl = new google.feeds.FeedControl();
          feedControl.addFeed("http://feeds.feedburner.com/IeeeSpectrum", "Latest IEEE Spectrum News:");
          feedControl.draw(document.getElementById("content"));
          feed.includeHistoricalEntries(); // tell the API we want to have old entries too
          feed.setNumEntries(25); // we want a maximum of 25 entries, if they exist

          feed.load(feedLoaded);
        }

        google.setOnLoadCallback(OnLoad);
    </script>

HTML:

        <body style="font-family: Arial;border: 0 none;">
            <div id="content">Loading IEEE Spectrum News...</div>
        </body>

我尝试使用feed.setNumEntries(),但它似乎不起作用。我感谢任何帮助。谢谢。

1 个答案:

答案 0 :(得分:1)

我找到了解决问题的方法:

<script type="text/javascript">

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

function initialize() {
  var control = new google.feeds.FeedControl();
  control.setNumEntries(25);
  control.addFeed("http://feeds.feedburner.com/IeeeSpectrum", "Latest IEEE Spectrum News:");
  control.draw(document.getElementById("content"));
}

google.setOnLoadCallback(initialize);

</script>