I am trying to use the free api provided by newsdata.io to get latest news.
When i hit the api with the fetch method in javascript. I am getting the following error
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://newsdata.io/api/1/news?apikey=xxxxxxxxxxx&q=technology&country=in,gb,us&language=en&category=technology. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)
My Java Script Code:
let res = "";
try {
res = await fetch("https://newsdata.io/api/1/news?apikey=xxxxxxxxxxxxxxx&q=technology&country=in,gb,us&language=en&category=technology", {
method: 'GET', // or 'PUT'
//mode: "no-cors",
headers: {
'Content-Type': 'application/json',
'Authorization': 'Token ' + token,
}
})
//news = Object.assign({}, await JSON.stringify(res.json()));
- Adding
mode: "no-cors"
to the fetch method It helped fetching the data but not allowing me to parse the data as a JSON.
Error: json.parse unexpected end of data at line 1 column 1 of the json data
Any help will be appreciated...