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

前端 未结 11 1420
再見小時候
再見小時候 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:41

    The API is write-only and is not intended to retrieve posts (Medium staff told me)

    You can simply use the RSS feed as such:

    https://medium.com/feed/@your_profile
    

    You can simply get the RSS feed via GET, then if you need it in JSON format just use a NPM module like rss-to-json and you're good to go.

    0 讨论(0)
  • 2021-01-30 04:41
    const MdFetch = async (name) => {
      const res = await fetch(
        `https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/${name}`
      );
      return await res.json();
    };
    

    const data = await MdFetch('@chawki726');

    0 讨论(0)
  • 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);
        }
      });
    });
    
    0 讨论(0)
  • 2021-01-30 04:49

    Check this One you will get all info about your own post........

    mediumController.getBlogs = (req, res) => {
        parser('https://medium.com/feed/@profileName', function (err, rss) {
            if (err) {
                console.log(err);
            }
    
            var stories = [];
    
            for (var i = rss.length - 1; i >= 0; i--) {
    
                var new_story = {};
    
                new_story.title = rss[i].title;
                new_story.description = rss[i].description;
                new_story.date = rss[i].date;
                new_story.link = rss[i].link;
                new_story.author = rss[i].author;
                new_story.comments = rss[i].comments;
    
                stories.push(new_story);
            }
            console.log('stories:');
            console.dir(stories);
            res.json(200, {
                Data: stories
            })
        });
    
    }
    
    0 讨论(0)
  • 2021-01-30 04:58

    I have built a basic function using AWS Lambda and AWS API Gateway if anyone is interested. A detailed explanation is found on this blog post here and the repository for the the Lambda function built with Node.js is found here on Github. Hopefully someone here finds it useful.

    0 讨论(0)
  • 2021-01-30 04:59

    With that REST method you would do this: GET https://api.medium.com/v1/users/{{userId}}/publications and this would return the title, image, and the item's URL. Further details: https://github.com/Medium/medium-api-docs#32-publications .

    You can also add "?format=json" to the end of any URL on Medium and get useful data back.

    0 讨论(0)
提交回复
热议问题