如何使用Medium API检索用户的帖子?

该文档显示了一个POST端点来创建博客帖子,但是对相应端点的GET请求会导致错误。

最佳答案

您可以通过使用RSS feed获得用户的帖子:

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



  使用Medium API v1(当前)无法检索用户或出版物。中级人员告诉我,这是故意写的。可以列出一些内容,例如贡献者和出版物,但不能列出帖子及其内容。在这种情况下,将使用RSS feed。


例如,一个受欢迎的个人资料:

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


您也可以将其用于出版物:

https://medium.com/feed/desk-of-van-schneider


这是使用Express和parse-rss NPM模块的示例:

var parser = require('parse-rss');

router.get('/blog', function(req, res, next) {

    parser('https://medium.com/feed/@vanschneider', 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.render('somepage',
        {
            stories: stories,
        });
    });
});

07-28 02:28
查看更多