Tags on Medium help organize and classify articles, making it easier for readers to find content related to specific topics.
This guide demonstrates how to fetch detailed information about a specific tag on Medium, such as the number of followers, related articles, and subcategories.
To run this code successfully, ensure the following are in place:
.env file to securely store your API key.medium-api-js package for interacting with Medium’s API.dotenv package for managing environment variables.npm install medium-api-js dotenvThis script retrieves information about the 'technology' tag using the Medium API. Let’s break it down step by step:
import Medium from 'medium-api-js';
import dotenv from 'dotenv';Medium: The library provides methods to interact with Medium’s API.dotenv: This package helps load environment variables from a .env file into process.env.dotenv.config();dotenv.config(): Reads the .env file and adds the RAPIDAPI_KEY to the environment variables..env file contains the following line:RAPIDAPI_KEY=your_rapidapi_key_hereconst medium = new Medium(process.env.RAPIDAPI_KEY);Medium(process.env.RAPIDAPI_KEY): Creates an instance of the Medium API client, using the API key from the environment variables.medium.getTagInfo('technology')
.then(data => {
console.log('Tag Info:', data);
});medium.getTagInfo('technology'): Fetches detailed information about the ‘technology’ tag..then(data => ...): Handles the API response and logs the tag information to the console.To execute the script, run the following command in your terminal:
node getTagInfo.jsWhen the code runs successfully, it outputs detailed information about the 'technology' tag. Here’s an example:
Fetching tag information from Medium provides valuable insights for content creators, marketers, and researchers. By leveraging the Medium API, you can automate the retrieval of tag data and integrate it into your workflow.
If you have any questions about the Medium API or this code, feel free to reach out to me at nishu@mediumapi.com.
Happy coding!