(Using Medium API Python Package)
This guide will show you how to use the Medium API to search for articles on the Medium platform. You'll learn to set up your environment, make a search request, and handle the response to extract and display relevant information.
Before we dive into the code, ensure you have the medium-api
Python package installed. You can install it using the following command:
pip install medium-api
Begin by importing the necessary libraries. You'll need the os
library to manage environment variables and the Medium
class from the medium_api
package to interact with the Medium API.
The API key is crucial for authenticating your requests to the Medium API. You need to set up an environment variable for the API key. Fetch it using the os.getenv
function.
Instantiate a Medium
object with your API key. This object will be used to interact with the Medium API.
Use the search_articles
method to search for articles. In this example, we're searching for articles related to "startup." The save_info
parameter is set to True
, which is useful if you have a high number of API calls available.
Iterate through the search results and print out the title and subtitle of each article. This step helps you quickly view the articles that match your query.
Here's what you can expect to see when you run the script:
With these steps, you can effectively search for Medium articles based on your query and retrieve relevant information using the Medium API. Make sure to handle API keys securely and manage your API call limits to avoid disruptions in your service.