0

I cannot seem to get this to work.

axios.get('https://medium.com/@mysite/latest?format=json')
  .then(function (response) {
    console.log(response);
  })

I get a cors error there does not seem any api to pull down my latest posts. Is this possible or does Medium not allow it?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192
  • 1
    You need to make the request through a proxy. See the answers at https://stackoverflow.com/questions/44468743/how-to-call-medium-rss-feed-from-localhost/44469188#44469188 and https://stackoverflow.com/questions/47759184/error-while-trying-to-access-public-stories-from-medium-api-on-client-side/47765090#47765090 – sideshowbarker Jun 19 '18 at 16:57

2 Answers2

0

Answer is this is possible, though Medium does not allow you to fetch articles on client side because of that CORS.

There are a few options to work around this:
* Cleanest one is to move the fetching to your server side, just use a client to render the list
* You can fetch the list via a cors proxy server, like cors-anywhere or cors.now
* You can make use of serverless tools like firebase-functions to help you fetch the article list

So the main idea is basically the same, fetching the list through a proxy (either it's your own server or it's on the cloud if you just want a client app)

eriknguyen
  • 520
  • 4
  • 13
0

You could use the feed API and then convert it with rss2json:

fetch("https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@freecodecamp")
  .then((res) => res.json())
  .then((data) => {
    const res = data.items;
    const posts = res.filter(item => item.categories.length > 0).sort((a, b) => {
      return new Date(b.pubDate) - new Date(a.pubDate);
    });
    console.log(posts.shift());
  });