49

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 how to retrieve publications and create posts, but it doesn't mention retrieving posts. Is retrieving posts/stories for a user currently possible using the Medium's API?

Tomas Romero
  • 8,418
  • 11
  • 50
  • 72
  • 2
    does not seem possible for now. Apparently you can only list publications and add a post to a publication. (but you can't even change a post after you created it, and the POST endpoint does not return a Location header with the url to the newly created post.) – njzk2 Mar 19 '16 at 03:52

11 Answers11

83

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.

Antonio Brandao
  • 1,353
  • 13
  • 19
  • 2
    I made a microservice wrapper for the rss-to-json package Antonio was mentioning above that also makes it easy to pull that data down: https://clay.run/services/nicoslepicos/rss-to-json. If you wanted to parameterize it so the endpoint always just pulls down some specific feed, just fork this endpoint with `clay fork nicoslepicos/rss-to-json` and then just put in the hardcoded feed you want it to always return. Alternatively, there's this other microservice: https://clay.run/services/nicoslepicos/medium-get-users-posts, which uses the Medium RSS feed specifically. – nicoslepicos Mar 06 '17 at 21:45
  • Is it possible to get medium's front page stories with RSS or something? – The Onin May 02 '17 at 15:46
  • 11
    not all the medium posts from an author show in the feed – Robert Tomas G IV Dec 30 '19 at 22:53
  • 3
    How to get the next page of a medium feed? – Gurleen Sethi Feb 07 '21 at 05:28
  • Btw, I create a project that you can embed medium articles into your Readme. Check it out: https://github.com/tonynguyenit18/github-readme-social-article – Tony Nguyen Apr 04 '21 at 01:20
  • SOmeone knows how to get older psots from medium programaticvally. The feed only shows the last ten posts but not older posts. – Ricker Silva Oct 20 '22 at 13:49
  • Lord Why. Won't. XML. Just. Die? – Ronnie Royston Jan 05 '23 at 21:37
13

Edit:

It is possible to make a request to the following URL and you will get the response. Unfortunately, the response is in RSS format which would require some parsing to JSON if needed.

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

⚠️ The following approach is not applicable anymore as it is behind Cloudflare's DDoS protection.

If you planning to get it from the Client-side using JavaScript or jQuery or Angular, etc. then you need to build an API gateway or web service that serves your 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);
    }
  });
});
Hardik Pithva
  • 1,729
  • 1
  • 15
  • 31
11

Nowadays this URL:

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

sits behind Cloudflare's DDoS protection service so instead of consistently being served your feed in JSON format, you will usually receive instead an HTML which is suppose to render a website to complete a reCAPTCHA and leaving you with no data from an API request.

And the following:

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

has a limit of the latest 10 posts.

I'd suggest this free Cloudflare Worker that I made for this purpose. It works as a facade so you don't have to worry about neither how the posts are obtained from source, reCAPTCHAs or pagination.

Full article about it.

Live example. To fetch the following items add the query param ?next= with the value of the JSON field next which the API provides.

  • I was using your solution, but I think they recently modified something on their end that made the solution not work anymore :( – Rubens Pinheiro Oct 05 '20 at 12:57
  • `https://medium.com/feed/@username` also includes data of comments I have made on my own or other stories. So separating them from actual stories is not possible it seems – Biboswan Oct 22 '20 at 08:42
10

To get your posts as JSON objects

you can replace your user name instead of @USERNAME.

https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@USERNAME

Sabesan
  • 654
  • 1
  • 10
  • 17
9
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');

U.A
  • 2,991
  • 3
  • 24
  • 36
6

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.

Casper Voogt
  • 111
  • 1
  • 8
  • 7
    it's tricky but when they say "publications" they don't mean "user's posts". As Antonio says the only way to access user's posts is through RSS. [See this issue](https://github.com/Medium/medium-api-docs/issues/51) – damko Jan 28 '17 at 02:37
4

Use this url, this url will give json format of posts
Replace studytact with your feed name

https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/studytact

SHUBHAM SINGH
  • 371
  • 3
  • 11
2

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.

Mark Fasel
  • 197
  • 2
  • 8
  • Wrapped that AWS Lambda you created into a Clay microservice. Also, as a heads up tried to send you an email to tell you about it but looks like the email on your site is bouncing back :) – nicoslepicos Mar 06 '17 at 21:46
1

(Updating the JS Fiddle and the Clay function that explains it as we updated the function syntax to be cleaner)

I wrapped the Github package @mark-fasel was mentioning below into a Clay microservice that enables you to do exactly this:

Simplified Return Format: https://www.clay.run/services/nicoslepicos/medium-get-user-posts-new/code

I put together a little fiddle, since a user was asking how to use the endpoint in HTML to get the titles for their last 3 posts: https://jsfiddle.net/h405m3ma/3/

You can call the API as:

curl -i -H "Content-Type: application/json" -X POST -d '{"username":"nicolaerusan"}' https://clay.run/services/nicoslepicos/medium-get-users-posts-simple

You can also use it easily in your node code using the clay-client npm package and just write:

Clay.run('nicoslepicos/medium-get-user-posts-new', {"profile":"profileValue"})
.then((result) => {

  // Do what you want with returned result
  console.log(result);

})
.catch((error) => {

  console.log(error);

});

Hope that's helpful!

nicoslepicos
  • 505
  • 1
  • 5
  • 9
0

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
        })
    });

}
Yash
  • 104
  • 2
  • 9
0

I have created a custom REST API to retrieve the stats of a given post on Medium, all you need is to send a GET request to my custom API and you will retrieve the stats as a Json abject as follows: Request :

curl https://endpoint/api/stats?story_url=THE_URL_OF_THE_MEDIUM_STORY

Response:

{
   "claps": 78,
   "comments": 1
}

The API responds within a reasonable response time (< 2 sec), you can find more about it in the following Medium article.

FrenchTechLead
  • 1,118
  • 3
  • 13
  • 20