The Medium RSS Feed’s Lacking Half | by Sabesan Sathananthan | Geek Tradition | Jun, 2022

0
1

ef7f

ef7f retrieves the stats (clapCount, voterCount, ef7f responseCount, and readingTime) of Medium ef7f posts

ef7f Picture by ef7f Ryoji Iwata ef7f on ef7f Unsplash

ef7f On this article, I’ll clarify ef7f how one can retrieve the ef7f stats ( ef7f claps rely ef7f , ef7f voter rely ef7f , ef7f response rely ef7f , and ef7f studying time ef7f ) of Medium feed posts ef7f utilizing a REST API, the ef7f shortage of this function within ef7f the Medium RSS feed is ef7f what motivated me to create ef7f this superior Medium API. That ef7f is my forty first Medium ef7f article.

ef7f I wished to acquire the ef7f stats ( ef7f claps rely ef7f , ef7f voter rely ef7f , ef7f response rely ef7f , and ef7f studying time ef7f ) of my Medium posts ef7f whereas engaged on my private ef7f web site improvement. 2 years ef7f earlier than after I implement ef7f the medium widget to my ef7f web site I discovered ef7f Pixelpoint.io ef7f which generated a widget ef7f with clap counts of a ef7f medium put up. At that ef7f second I questioned how they ef7f carried out it? Then I ef7f neglect to analysis it however ef7f final month I discovered that ef7f pixelpoint.io’s widget shouldn’t be working. ef7f I regarded all over the ef7f place for an answer to ef7f my wants however couldn’t discover ef7f one, so I had no ef7f selection however to code it ef7f myself.

ef7f My preliminary instinct was to ef7f have a look at the ef7f RSS feed however there have ef7f been no such particulars are ef7f supplied then I regarded on ef7f the official documentation of the ef7f general public ef7f REST API ef7f by Medium, and nothing ef7f was there both. The Medium ef7f REST API solely permits you ef7f to create a Medium article ef7f by ef7f HTTP POST ef7f methodology(cf ef7f part 3.3 ef7f ). ef7f You possibly can’t retrieve or ef7f edit a Medium article through ef7f the use of the Medium ef7f API 😔.

ef7f To be able to get ef7f an understanding of how the ef7f helpful stats are retrieved within ef7f the Medium put up, I ef7f began to examine the Medium ef7f utilizing browser developer instruments. Shockingly, ef7f there was no request to ef7f acquire the stats amongst all ef7f of the XHR calls, which ef7f push me to have a ef7f look at the HTML response ef7f of the Medium put up.

ef7f Inspecting a Medium put up ef7f web page.
 ef7f curl  ef7f https://medium.com/p/unique_Id_of_the_post ef7f  >> put up.html

ef7f As a javascript variable, the ef7f claps rely, voter rely, response ef7f rely, and studying time are ef7f instantly injected into the HTML ef7f response. You possibly can confirm ef7f that by typing ef7f console.log(window.__APOLLO_STATE__); ef7f within the Javascript console of ef7f the Put up web page.

ef7f window.__APOLLO_STATE__ object

ef7f Then I scrape these helpful ef7f stats utilizing ef7f request ef7f and ef7f cheerio ef7f .

ef7f Picture by ef7f Kike Salazar N ef7f on ef7f Unsplash

ef7f In a medium put up, ef7f knowledge comes as JSON in ef7f a script tag. Through the ef7f use of javascript, these knowledge ef7f are picked up and rendered ef7f in DOM on the browser-side. ef7f Normally, knowledge in a script ef7f tag takes this kind:

ef7f Then I scrape Medium put ef7f up knowledge with no headless ef7f browser.

ef7f First, I get the web ef7f site and search for errors. ef7f Then I confirmed whether or ef7f not the physique exists, and ef7f cargo the physique utilizing ef7f cheerio ef7f in ef7f $ ef7f . In ef7f attempt ef7f block, all of the ef7f tag script contents are mapped ef7f in an array. Then discover ef7f the ingredient which incorporates ef7f window.__APOLLO_STATE__ ef7f , change the project ef7f ef7f window.__APOLLO_STATE__ = ef7f with an empty string. I ef7f change the ef7f /"/g ef7f with ‘ ef7f " ef7f ’ and parse with ef7f JSON.parse ef7f . Lastly, get the ef7f suitable values from the JSON.

ef7f Some great benefits of this ef7f system over headless browsers are ef7f tremendous quick and takes means ef7f much less processing and sources.

ef7f You would ready to make ef7f use of the ef7f Superior Medium API ef7f that I developed as ef7f follows:

ef7f There are 5 varieties of ef7f requests. you can have the ef7f ability to get all of ef7f the responses through the use ef7f of ef7f HTTP GET ef7f methodology.

ef7f Medium feed in JSON

ef7f You would in a position ef7f to get the RSS feed ef7f of the final 10 Medium ef7f posts through the use of ef7f the next hyperlinks (change your ef7f username as an alternative of ef7f ef7f @username ef7f ).

 ef7f medium.com/feed/@username 
ef7f or ef7f
ef7f username.medium.com/feed

ef7f The next request of the ef7f API offers the direct JSON ef7f conversion of that RSS Feed.

 ef7f curl  ef7f https://advanced-medium-api.herokuapp.com/medium/consumer/{userId}

ef7f Medium Superior Knowledge

ef7f You would in a position ef7f to get the Medium feed ef7f in JSON with the lacking ef7f a part of the Medium ef7f feed comparable to ef7f clapCount ef7f , ef7f voterCount ef7f , ef7f responseCount ef7f , ef7f readingTime ef7f . every lacking knowledge injected ef7f in each put up(gadgets) object.

ef7f The next request of the ef7f API offers the JSON conversion ef7f of the RSS feed with ef7f the injection of lacking knowledge.

 ef7f curl  ef7f https://advanced-medium-api.herokuapp.com/superior/consumer/{userId}

ef7f Medium Custom-made Knowledge

ef7f JSON conversion of the Medium ef7f RSS feed is personalized in ef7f line with the classes. Order ef7f the Medium put up’s tags ef7f in line with their use ef7f rely among the many newest ef7f 10 posts and the ef7f tagOrder ef7f return that tags’ order ef7f rank. Medium’s newest 10 posts ef7f have been divided by 3 ef7f and each 3 posts have ef7f been pushed in an array ef7f and people arrays have been ef7f pushed in a single array. ef7f There’s an algorithm that returns ef7f probably the most appropriate tag ef7f for the Medium put up ef7f among the many different tags ef7f of that Medium put up.

ef7f The next request of the ef7f API offers the personalized model ef7f of the Medium feed in ef7f JSON

 ef7f curl  ef7f https://advanced-medium-api.herokuapp.com/personalized/consumer/{userId}

ef7f Medium Custom-made Superior Knowledge

ef7f This response accommodates the Medium ef7f personalized knowledge with the injection ef7f of lacking stats comparable to ef7f ef7f clapCount ef7f , ef7f voterCount ef7f , ef7f responseCount ef7f , ef7f readingTime ef7f .

ef7f The next request of the ef7f API offers the personalized model ef7f of the Medium feed in ef7f JSON with the lacking a ef7f part of the Medium feed.

 ef7f curl  ef7f https://advanced-medium-api.herokuapp.com/superior/personalized/consumer/{userId}

ef7f Lacking knowledge of a selected ef7f put up.

ef7f This response accommodates solely the ef7f lacking half ( ef7f clapCount ef7f , ef7f voterCount ef7f , ef7f responseCount ef7f , ef7f readingTime ef7f ) of Medium feed for ef7f a selected Medium put up.

ef7f Request ef7f 💻 ➡ 🌎 ef7f :

 ef7f curl  ef7f https://advanced-medium-api.herokuapp.com/medium/put up/{postId}

ef7f Response ef7f 🌎➡💻 :

 ef7f {
ef7f "clapCount": 98,
ef7f "responseCount": 4,
ef7f "voterCount": 12,
ef7f "readingTime": 4
ef7f }

ef7f This API is ef7f Open Supply ef7f and I welcome your ef7f contributions. final 2 years I ef7f used the medium widget from ef7f ef7f Pixelpoint.io ef7f which generated a widget ef7f with clap counts of a ef7f medium put up. I didn’t ef7f do analysis to get the ef7f lacking a part of the ef7f Medium feed after I used ef7f Pixelpoint.io. however 2 months earlier ef7f than Pixelpoint.io shouldn’t be working ef7f and this incident impacts my ef7f private web site. Subsequently I ef7f pushed myself and created this ef7f API.

ef7f

LEAVE A REPLY

Please enter your comment!
Please enter your name here