(Using Medium API Python Package)
In this guide, we'll walk you through how to use the Medium API to fetch a
list of recommended articles for a specific Medium article. This process involves
setting up the Medium API, fetching an article, and then retrieving and displaying
its recommended articles. The only prerequisite is that you need to install
the medium-api
Python package. If you haven't installed it yet, you can do
so with the following command:
pip install medium-api
Let's dive into the Python code to understand each step.
First, you need to import the necessary libraries. In this case, you will import the os
library to handle environment variables and the Medium
class from the medium_api
package.
To interact with the Medium API, you'll need an API key. For security reasons, it's best to store this key in an environment variable. You can retrieve it using os.getenv()
.
Ensure you have set the RAPIDAPI_KEY
environment variable with your actual API key.
With your API key, you can now create an instance of the Medium
class. This object will be used to make requests to the Medium API.
To fetch recommended articles, you need to first get the Article
object by specifying its article_id
. Then, use the fetch_recommended_articles()
method to retrieve the list of recommended articles.
Replace "67fa62fc1971"
with the ID of the Medium article you are interested in.
Finally, loop through the list of recommended articles and print their titles along with their clap counts.
This loop will display each recommended article's title and the number of claps it has received, which can be useful for understanding the popularity of each recommendation.
By following these steps, you can easily fetch and display recommended articles for any given Medium article using the Medium API.