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

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

    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

    0 讨论(0)
  • 2021-01-30 05:01

    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

    0 讨论(0)
  • 2021-01-30 05:02

    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.

    0 讨论(0)
  • 2021-01-30 05:05

    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.

    0 讨论(0)
  • 2021-01-30 05:05

    (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!

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