(Using Medium API Python Package)
This guide will walk you through fetching newsletter-related information for a specific Medium publication using the Medium API. By the end of this article, you'll understand how to retrieve details such as the newsletter ID, name, description, slug, number of subscribers, and image URL.
Before we start, make sure you have the `medium-api` Python package installed. You can install it using pip:
install medium-api
First, you need to import the necessary libraries for interacting with the Medium API and handling environment variables. Here’s how you do it:
To authenticate with the Medium API, you need an API key. This key should be stored in an environment variable called `RAPIDAPI_KEY`. Retrieve this key using the `os.getenv()` function:
With the API key in hand, create an instance of the `Medium` class. This object will allow you to interact with the Medium API:
You’ll need the ID of the publication you want to fetch information from. Replace `"98111c9905da"` with the actual ID of the publication. Then, create a `Publication` object:
Finally, retrieve and print the newsletter information associated with the publication. The `save_info()` method updates the newsletter details, and you can then access various attributes:
This guide provided a step-by-step approach to fetching newsletter information from a Medium publication using the Medium API. By following these instructions, you can easily retrieve details such as the newsletter's ID, name, description, slug, subscriber count, and image URL.