Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Call Medium RSS Feed

Medium has an RSS feed available at https://medium.com/feed/[@username]. I'm trying to fetch all my blog posts using an XMLHTTPRequest. When I test on local, I run into CORs errors. When I turn on CORs Chrome extension, I get a 401 error. Any ideas? Has anyone succeeded in calling Medium RSS?

like image 683
Ksenia Avatar asked Dec 06 '22 14:12

Ksenia


1 Answers

To get https://medium.com/feed/[@username] content using XHR, you can make the XHR request through a proxy of some kind. For example, trying giving your current XHR code this URL:

https://cors-anywhere.herokuapp.com/https://medium.com/feed/@sideshowbarker

That’ll cause the request to go to https://cors-anywhere.herokuapp.com, a open/public CORS proxy which then sends the request on to https://medium.com/feed/@sideshowbarker.

And when that proxy gets the response, it takes it and adds the Access-Control-Allow-Origin response header to it and then passes that back to your requesting frontend code as the response.

That response with the Access-Control-Allow-Origin response header is what the browser sees, so the error message the browser is showing you now goes away, and the browser allows your frontend JavaScript code to access the response.

Or use the code from https://github.com/Rob--W/cors-anywhere/ or such to set up your own proxy.

The reason you need a proxy is, responses from https://medium.com/feed/[@username] don’t include the Access-Control-Allow-Origin response header, so your browser will refuse to let your frontend JavaScript code access those responses cross-origin.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS has more details.

like image 103
sideshowbarker Avatar answered Dec 25 '22 03:12

sideshowbarker