How to retrieve Medium stories for a user from the API?

前端 未结 11 1416
再見小時候
再見小時候 2021-01-30 04:06

I\'m trying to integrate Medium blogging into an app by showing some cards with posts images and links to the original Medium publication.

From Medium API docs I can see

11条回答
  •  隐瞒了意图╮
    2021-01-30 04:46

    If you planning to get it from Client side using JavaScript or jQuery or Angular, etc. then you need to build API gateway or web service that serves you feed. In the case of PHP, RoR or any server side that should not be the case.

    You can get it directly in JSON format as given beneath:

    https://medium.com/@yourhandle/latest?format=json    
    

    In my case, I made a simple web service in the express app and host it over Heroku. React App hits the API exposed over Heroku and gets the data.

    const MEDIUM_URL = "https://medium.com/@yourhandle/latest?format=json";
    
    router.get("/posts", (req, res, next) => {
      request.get(MEDIUM_URL, (err, apiRes, body) => {
        if (!err && apiRes.statusCode === 200) {
          let i = body.indexOf("{");
          const data = body.substr(i);
          res.send(data);
        } else {
          res.sendStatus(500).json(err);
        }
      });
    });
    

提交回复
热议问题