javascript 使用 AJAX 加载 RSS 提要:Google Feed API 的替代方案?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34049813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 17:11:17  来源:igfitidea点击:

Loading RSS feed with AJAX: alternatives to Google Feed API?

javascriptjqueryajaxapirss

提问by Joe Mornin

I've been using the Google Feed API to load RSS feeds, but it looks like Google has shut down the API. For instance, when I try to load the New York Times RSS feed at http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&q=http%3A%2F%2Frss.nytimes.com%2Fservices%2Fxml%2Frss%2Fnyt%2FHomePage.xml, I get this response:

我一直在使用 Google Feed API 加载 RSS 提要,但看起来 Google 已关闭该 API。例如,当我尝试在 加载纽约时报 RSS 提要时http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&q=http%3A%2F%2Frss.nytimes.com%2Fservices%2Fxml%2Frss%2Fnyt%2FHomePage.xml,我得到以下响应:

{"responseData": null, "responseDetails": "This API is no longer available.", "responseStatus": 403}

Are there any viable alternatives?

有没有可行的替代方案?

回答by Tony

Use Yahoo's YQL API:

使用雅虎的YQL API

select * from xml where url = 'https://news.ycombinator.com/rss'

You can request a JSONP feed by adding a callbackparameter to the url

您可以通过向callbackurl添加参数来请求 JSONP 提要

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%20%3D%20'https%3A%2F%2Fnews.ycombinator.com%2Frss'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=mycallback

回答by SpYk3HH

Deprecated

已弃用

Myplugin, $.jQRSSuses Google Feedand seems to work just fine, given your exact RSS link:

我的插件$ .jQRSS用途Google Feed,似乎工作得很好,给你确切的RSS链接:

var rss = 'http://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml';
$.jQRSS(rss, { count: 8 }, function (feed, entries) {
 console.log([feed, entries]);
 $.each(entries, function(i) {
  if (this['content']) {
   var fieldset = $('<fieldset/>', { title: this.contentSnippet }).appendTo('body'),
    legend = $('<legend/>').appendTo(fieldset),
    $link = $('<a />', { href: this.link, html: this.title, target: '_blank' }).appendTo(legend),
    $date = $('<h5 />', { html: this.publishedDate }).appendTo(fieldset),
    $content = $('<div />', { html: this.content }).appendTo(fieldset);
   $content.find('br').remove();
  }
 });
});
fieldset > h5 { float: right; margin-top: 0; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://rawgit.com/JDMcKinstry/jQRSS/master/jQRSS.js"></script>

回答by Dave B

One addition to Tony's solution for using YQL - I needed to change the callback value to JSON_CALLBACKto parse the response properly:

Tony 使用 YQL 的解决方案的一个补充 - 我需要将回调值更改为 JSON_CALLBACK以正确解析响应:

'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%20%3D%20\'' + encodeURIComponent(url) + '\'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=JSON_CALLBACK'

回答by coco puffs

You can use PHP to grab a copy of whatever RSS feed you wish to display, then use client side JavaScript to display the results. The main advantage is you're not subject to daily requests limits that way, which most free RSS API services have, or reliability issues.

您可以使用 PHP 获取您希望显示的任何 RSS 提要的副本,然后使用客户端 JavaScript 来显示结果。主要优点是您不受大多数​​免费 RSS API 服务所具有的每日请求限制或可靠性问题的限制。

http://www.javascriptkit.com/dhtmltutors/ajaxticker/index.shtml

http://www.javascriptkit.com/dhtmltutors/ajaxticker/index.shtml

回答by jmacuna

You can use the script feedburner:

您可以使用脚本 feedburner:

<script src="http://feeds.feedburner.com/feeduri?format=sigpro&nItems=10" type="text/javascript"></script>

<script src="http://feeds.feedburner.com/feeduri?format=sigpro&nItems=10" type="text/javascript"></script>

All information:

所有信息:

https://support.google.com/feedburner/answer/78991?hl=en

https://support.google.com/feedburner/answer/78991?hl=en