2

I want to fetch metadata (title, image, description) from a url like a Medium article and then display it as a post on my blog. How to do it. I am using ReactJS

I tried using fetch and axios.get but it always shows error in the browser's console. "NetworkError when attempting to fetch resource." "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://medium.com/s/jessica-valenti/hateful-fox-news-rhetoric-can-do-real-world-harm-52e26008caa5. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)"

Ankur Singh
  • 133
  • 1
  • 12

2 Answers2

6

Use open-graph-scraper and make the request from backend-server. It works like a delight

Ankur Singh
  • 133
  • 1
  • 12
1

You are not allowed to request request URL's that don't have the CORS header (Access-Control-Allow-Origin: *). This is due security reasons of medium and other pages. They need to actively enable that header to allow clients to request it from JS.

You will need a backend that does the request for you (nodejs, python, php etc). You could also try to use https://cors-anywhere.herokuapp.com.

Tobias Lins
  • 2,543
  • 19
  • 22