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

时间:2015-12-02 18:02:32

标签: javascript jquery ajax api rss

我一直在使用Google Feed API来加载RSS Feed,但Google似乎已经关闭了API。例如,当我尝试在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加载纽约时报RSS源时,我得到了这样的答复:

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

有没有可行的替代方案?

5 个答案:

答案 0 :(得分:27)

使用Yahoo YQL API

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

您可以通过向网址

添加callback参数来请求JSONP Feed
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

答案 1 :(得分:3)

<强> 已过时

My plugin$.jQRSS使用Google Feed并且似​​乎工作得很好,给出了您的确切RSS链接:

&#13;
&#13;
model(params) {
    this.set('routeParams',params.event_url);
    return Ember.RSVP.hash({
      event: null,
      items: null
    });
},
actions: {
  didTransition() {
     this.store.findRecord('event',this.get('routeParams')).then((result)=>{
        this.controller.set('model.event',result);
     });
     this.controller.set('noItems',false);
     this.store.query('cart',{auction_id:this.get('routeParams'),user:this.get('user.user.user_id'),combine:true}).then((result)=>{
        if(!result.get('length')){
      this.controller.set('noItems',true);
      return null;
        }else{
      this.controller.set('model.items',result);
    }
    });
  },
}
&#13;
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();
		}
	});
});
&#13;
fieldset > h5 { float: right; margin-top: 0; }
&#13;
&#13;
&#13;

答案 2 :(得分:2)

Tony使用YQL的解决方案的一个补充 - 我需要change the callback value to 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'

答案 3 :(得分:1)

您可以使用脚本feedburner:

&lt; script src =&#34; http://feeds.feedburner.com/feeduri?format = sigpro&amp; nItems = 10&#34;类型=&#34;文本/ JavaScript的&#34;&GT;&LT; /脚本&GT;

所有信息:

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

答案 4 :(得分:1)

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

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