(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.
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
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.
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.
Initialize a Medium object with your API key. This object will allow you to make API requests.
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.
Finally, iterate over the publications that the user is following and print each publication's name.
To see the output of the above code, refer to the following gist: