How to Get Media Assets from a Medium Article

(Using Medium API Python Package)

If you need to extract and view the assets (such as images, videos, and GitHub gists) from a Medium article, this guide will walk you through the process using the medium-api Python library. Make sure you have Python installed and follow these steps to get started.

Prerequisites

Before you begin, ensure you have the medium-api library installed. You can install it using pip:

pip install medium-api

Step-by-Step Guide

1. Import Required Libraries

First, you'll need to import the necessary libraries. In this case, you'll use os for handling environment variables and medium_api for interacting with the Medium API.

2. Get Your API Key

You'll need to obtain your API key from Medium and set it as an environment variable. In this script, we retrieve the API key using os.getenv.

Make sure to replace 'RAPIDAPI_KEY' with the actual environment variable name if it's different.

3. Create a Medium Object

With your API key, create an instance of the Medium class. This object will be used to interact with the Medium API.

4. Retrieve the Article

To get the article's assets, you need to retrieve the article object. Replace "b7d838c84f72" with the actual article ID you want to work with.

5. Extract and Print Asset URLs

Now you can access the assets in the article. The following code extracts and prints URLs for images, YouTube videos, and GitHub gists:

Summary

In this guide, you learned how to use the medium-api library to extract and view various assets from a Medium article. By following these steps, you can easily retrieve image URLs, YouTube video links, and GitHub gists embedded in any article on Medium.

Output