How to Get Responses from a Medium Article

(Using Medium API Python Package)

This guide will walk you through the process of fetching responses (comments) from a Medium article using the Medium API. We'll be using Python for this task, so make sure you have pip install medium-api installed.

Prerequisite

Before we start, ensure that you have the medium-api library installed. You can install it using the following command:

pip install medium-api

Steps to Fetch Article Responses

1. Import Necessary Libraries

Begin by importing the required libraries. You'll need the os library to access environment variables and the Medium class from the medium_api package.

2. Retrieve Your API Key

Fetch your API key from the environment variables. This key is necessary for authenticating your requests to the Medium API.

3. Create a Medium Object

Use the retrieved API key to create an instance of the Medium class. This object will be used to interact with the Medium API.

4. Fetch Article Responses

You need the unique article ID to fetch responses. Create an article object by providing the article ID, then call the fetch_responses() method to retrieve the responses.

Replace "67fa62fc1971" with the actual ID of the Medium article you're interested in.

5. Print the Responses

Finally, iterate over the responses and print their content. This will display each response (or comment) from the article.

The --- separator helps to clearly delineate between individual responses.

And that's it! You now know how to fetch and print responses from a Medium article using Python and the Medium API.

Output

To see the output of the script, you can refer to the following gist: