(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.
Before we start, ensure that you have the medium-api
library installed. You can install it using the following command:
pip install medium-api
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.
Fetch your API key from the environment variables. This key is necessary for authenticating your requests to the Medium API.
Use the retrieved API key to create an instance of the Medium
class. This object will be used to interact with the Medium API.
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.
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.
To see the output of the script, you can refer to the following gist: