Medium is one of the most popular platforms for sharing articles and ideas, ranging from technical content to personal stories.
For developers and data enthusiasts, fetching detailed information about a Medium article can be incredibly useful for analytics, content curation, or simply learning more about the article’s metadata.
This guide explains how to retrieve detailed information about a Medium article such as its title, author, publication date, tags, claps, and more using the medium-api-js
package.
Before you start, make sure you have the following:
medium-api-js
Library: Install the Medium API wrapper for JavaScript by running:npm install medium-api-js dotenv
dotenv
: Create a .env
file in your project directory to securely store your RapidAPI key:RAPIDAPI_KEY=your_rapidapi_key_here
The code begins by importing the necessary libraries. The medium-api-js
package is used to interact with the Medium API, and dotenv
is used to manage environment variables securely.
import Medium from 'medium-api-js';
import dotenv from 'dotenv';
dotenv.config();
Medium
: This is the main library to interact with Medium’s API.dotenv
: Enables loading environment variables from the .env
file to keep sensitive data secure.Next, initialize the Medium client using your RapidAPI key:
const medium = new Medium(process.env.RAPIDAPI_KEY);
Here, the API key is retrieved from the .env
file, ensuring security and ease of configuration.
You need to know the article ID for which you want to fetch information. The ID is typically part of the article’s URL.
const articleId = '67fa62fc1971';
For instance, if the article URL is:
https://medium.com/some-publication/why-its-super-hard-to-be-an-ml-researcher-or-developer-67fa62fc1971
The article ID is 67fa62fc1971
.
Call the getArticleInfo
method with the article ID to fetch detailed information:
medium.getArticleInfo(articleId).then(data => {
console.log('Article Info:', data);
});
getArticleInfo
: A method provided by medium-api-js
to retrieve detailed metadata about an article.data
: The response object containing article details, which is then logged to the console.To execute the code, run the following command in your terminal:
node getArticleInfo.js
Ensure that your .env
file is configured correctly and that you have a valid article ID.
When you run the script, you’ll get a detailed response containing various metadata about the article. Here’s an example of the output:
Fetching Medium article information is a powerful way to gain insights into the platform’s content.
Whether you’re a developer building analytical tools, a writer analyzing your own work, or a content curator, this guide equips you to interact with Medium’s API effectively.
If you have any questions about the Medium API or this implementation, feel free to reach out to nishu@mediumapi.com.