I'm using this jQuery plugin (fiddle) to read Google news rss feed. It requires converting the feed to json format. Then I came across this thread that shows a Google feed in JSON format without the help of Yahoo Pipe:
.0&q=http%3A%2F%2Fnews.google%2Fnews%3Foutput%3Drss%26num%3D8
I tried the plugin's method to parse the JSON Google feed but failed. Can anyone show me the correct way to read that feed?
My attempt:
<script>
$('#rssdata').ready(function()
{
var pipe_url = '.0&num=8&q=http%3A%2F%2Fnews.google%2Fnews%3Foutput%3Drss';
$.getJSON(pipe_url,function(data)
{
$(data.feed.entries).each(function(index,entry)
{
var item_html = '<li><a target="_blank" href="'+entry.link+'">'+entry.title+'</a></li>';
$('#rssdata ul.rss-items').append(item_html);
});
$('#rssdata div.loading').fadeOut();
$('#rssdata ul.rss-items').slideDown();
});
});
</script>
Google News Feed:
{"responseData": {"feed":{"feedUrl":"\u003drss\u0026num\u003d8","title":"Top Stories - Google News","link":"\u003d1\u0026amp;ned\u003dus\u0026amp;hl\u003den\u0026amp;num\u003d8","author":"","description":"Google News","type":"rss20","entries":[{"title":"Malaysia Airlines loses contact with plane en route to Beijing with 239 aboard - CBS News","link":"http://....
I'm using this jQuery plugin (fiddle) to read Google news rss feed. It requires converting the feed to json format. Then I came across this thread that shows a Google feed in JSON format without the help of Yahoo Pipe:
http://ajax.googleapis./ajax/services/feed/load?v=1.0&q=http%3A%2F%2Fnews.google.%2Fnews%3Foutput%3Drss%26num%3D8
I tried the plugin's method to parse the JSON Google feed but failed. Can anyone show me the correct way to read that feed?
My attempt:
<script>
$('#rssdata').ready(function()
{
var pipe_url = 'http://ajax.googleapis./ajax/services/feed/load?v=1.0&num=8&q=http%3A%2F%2Fnews.google.%2Fnews%3Foutput%3Drss';
$.getJSON(pipe_url,function(data)
{
$(data.feed.entries).each(function(index,entry)
{
var item_html = '<li><a target="_blank" href="'+entry.link+'">'+entry.title+'</a></li>';
$('#rssdata ul.rss-items').append(item_html);
});
$('#rssdata div.loading').fadeOut();
$('#rssdata ul.rss-items').slideDown();
});
});
</script>
Google News Feed:
{"responseData": {"feed":{"feedUrl":"http://news.google./news?output\u003drss\u0026num\u003d8","title":"Top Stories - Google News","link":"http://news.google./news?pz\u003d1\u0026amp;ned\u003dus\u0026amp;hl\u003den\u0026amp;num\u003d8","author":"","description":"Google News","type":"rss20","entries":[{"title":"Malaysia Airlines loses contact with plane en route to Beijing with 239 aboard - CBS News","link":"http://....
Share
Improve this question
edited May 23, 2017 at 12:15
CommunityBot
11 silver badge
asked Mar 8, 2014 at 19:21
RedGiantRedGiant
4,76911 gold badges63 silver badges151 bronze badges
1
- This is great. I want to get the news feed from google which is related to one pany lets say as Microsoft. How to get only news feed related to only Microsoft? – Mihir Commented Oct 16, 2014 at 9:39
1 Answer
Reset to default 3Your code is not working because of the Same-origin policy.
One possible solution is to use JSONP
which is supported by Google News Feed API.
So you can do:
$('#rssdata').ready(function () {
$.ajax({
url: 'http://ajax.googleapis./ajax/services/feed/load?v=1.0&num=8&q=http%3A%2F%2Fnews.google.%2Fnews%3Foutput%3Drss',
dataType: 'jsonp',
success: function (data) {
//console.log(data.feed.entries);
$(data.responseData.feed.entries).each(function (index, entry) {
var item_html = '<li><a target="_blank" href="' + entry.link + '">' + entry.title + '</a></li>';
$('#rssdata ul.rss-items').append(item_html);
});
$('#rssdata div.loading').fadeOut();
$('#rssdata ul.rss-items').slideDown();
},
error: function () {}
});
});
Updated Fiddle
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745657502a4638630.html
评论列表(0条)