(Using Medium API Python Package)
This guide will show you how to use the Medium API to fetch and display recently published articles from a Medium publication using Python. Follow these steps to accomplish this task.
Before you start, make sure you have the code medium-api
package installed. You can install it using the following command:
pip install medium-api
First, import the necessary libraries:
Next, fetch your Medium API key from an environment variable:
Ensure that the RAPIDAPI_KEY
environment variable is set with your Medium API key.
Create an instance of the Medium
class using the API key:
This object allows you to interact with the Medium API.
Define the Medium publication you want to access:
Replace "98111c9905da"
with the ID of the Medium publication you are interested in. The save_info=False
parameter indicates that publication details are not saved locally.
Retrieve and print articles published within the last week with the following code:
This snippet fetches articles published between the current date and one week prior, then prints each article's title along with its publication date.
By following these steps, you can easily retrieve and display recent articles from a Medium publication using Python and the Medium API.