How to Get Medium Publications a User is Following

(Using Medium API Python Package)

If you want to get a list of publications that a specific user is following on Medium, you can achieve this using the Medium API with Python. Below, we'll walk through a step-by-step guide on how to use the Medium API to accomplish this task.

Prerequisite

Before we dive into the code, you need to have the medium-api library installed. You can install it using pip:

pip install medium-api

Step-by-Step Guide

1. Import Libraries

Begin by importing the necessary libraries. The os module helps in accessing environment variables, and the Medium class from medium_api is used to interact with Medium's API.

2. Get API Key

You need an API key to authenticate your requests to the Medium API. This key should be stored in your environment variables. The code retrieves the API key from the environment variable RAPIDAPI_KEY.

3. Create a Medium Object

Initialize a Medium object with your API key. This object will allow you to make API requests.

4. Fetch User's Publications

Create a User object for the specific Medium username you're interested in. The fetch_publication_following method retrieves the list of publications that the user is following.

5. Display the Results

Finally, iterate over the publications that the user is following and print each publication's name.

Output

To see the output of the above code, refer to the following gist: