1

I am trying to create a react App where I need to parse some RSS news feeds from url "https://news.google.com/news/rss" but I am getting an error "request has been blocked by CORS policy: "No 'Access-Control-Allow-Origin' header is present on the requested resource". I did the similar project in Android app where I fetched some feeds using AsyncTasks in java it didn't showed me any CORS issue, I want to understand why it worked on Android app and not in Web Application? Is it the browser that is enforcing the CORS or is the google server that is enforcing some sort of CORs policy?

let xmlText;
axios
.get(
  "https://news.google.com/news/rss",
)
.then((response) => {
  xmlText = response;
  return response;
})
.then((textResponse) => {
  console.log("Fetching response as", textResponse);
  xmlText = textResponse;
})
.catch((error) => {
  console.log(error);
});
  • Did you make any headway on this? Im running into the same problem. It doesn't make sense to me why I can load the feed in the browser, but a fetch request fails to cors... – Ryhnn Nov 18 '22 at 14:13

1 Answers1

3

You can use a plugin google-news-json

Google News JSON API


Installation

npm install --save google-news-json

Or

yarn add google-news-json

Usage Usage example:

let googleNewsAPI = require("google-news-json");
let news = await googleNewsAPI.getNews(googleNewsAPI.TOP_NEWS, null, "en-GB");

Also supports callback

googleNewsAPI.getNews(googleNewsAPI.SEACRH, "apple", "en-GB", (err,response) => {
console.log(response);
   });

Parameters Method (defaults to TOP_NEWS or HIGHLIGHTS)

Query (this is ignored when method is TOP_NEWS or HIGHLIGHTS)

Locale (defaults to en-GB)

Callback (not required)

Methods

HIGHLIGHTS, TOP_NEWS, LOCATION, SEARCH, TOPIC, GEO

Supported TOPICS

TOPICS_WORLD, TOPICS_NATION, TOPICS_BUSINESS, TOPICS_TECHNOLOGY, TOPICS_ENTERTAINMENT, TOPICS_SCIENCE, TOPICS_SPORTS, TOPICS_HEALTH

  • 1
    Thank you very much for your quick detailed answer. For my other question I got the answer/understanding from various posts. One of them is below if any has similar doubts: https://stackoverflow.com/questions/36958999/cors-is-it-a-client-side-thing-a-server-side-thing-or-a-transport-level-thin – Ashin Abbasi Dec 30 '21 at 22:30
  • thank you very match,bro – Mahmoud Al-samman Dec 31 '21 at 13:04