How to Get Medium Publications a User is Following

Using Javascript

If you want to explore which Medium publications a specific user is following, this guide walks you through a straightforward method to fetch this data using the "medium-api-js" library.

By the end of this article, you will know how to set up, run, and understand a script that retrieves this information. This can be particularly useful for analyzing user interests or curating content recommendations.

Prerequisites

Before diving into the code, ensure you have the following:

Setting Up the Environment

First, install the required packages:

npm install medium-api-js dotenv

Then, create a .env file in your project directory and add your RapidAPI key:

RAPIDAPI_KEY=your_rapidapi_key_here

Code Explanation

Let’s break down the script into smaller sections for clarity.

Importing Required Modules

import Medium from 'medium-api-js';
import dotenv from 'dotenv';

dotenv.config();

Here:

Initializing the Medium API

const medium = new Medium(process.env.RAPIDAPI_KEY);

This line creates an instance of the Medium class, passing in the RAPIDAPI_KEY from the environment variables to authenticate API requests.

Defining the User ID

const userId = '1985b61817c3';

The userId variable stores the Medium User ID for which we want to fetch publication following data. Replace '1985b61817c3' with the actual User ID of the target user.

Fetching Publication Following Data

medium.getUserPublicationFollowing(userId)
    .then(data => console.log('User Publication Following:', data));

Here:

Running the Script

Save the script to a file named getUserPublicationFollowing.js. Open your terminal and run the script:

node getUserPublicationFollowing.js

Output Explanation

When the script runs successfully, it will fetch and display the publications the user is following. For example:

This output includes:

Potential Use Cases

Summary

Fetching the list of publications a Medium user follows is simple and insightful with the medium-api-js library. This functionality can help developers and marketers alike to better understand user preferences and create engaging content strategies.

If you have any questions or need assistance with the Medium API, feel free to reach out to me at nishu@mediumapi.com.

nishu@mediumapi.com