How to Publish an Article to Medium Using Python and the Medium API
type
status
date
slug
summary
tags
category
icon
Introduction
As someone who uses Obsidian to write articles, I often find myself needing to copy and format my content manually when publishing to Medium. This process can be time-consuming and repetitive, especially when dealing with Markdown files. To streamline my workflow, I decided to develop a Python script that automates the publication of Markdown files directly to Medium. In this article, I’m excited to share with you how to programmatically publish articles using the Medium API, making the process faster and more efficient.
Setting Up the Medium API
To interact with Medium’s API, you first need to generate an integration token. This token will allow your Python script to authenticate and perform actions on your behalf.
Steps to Generate an Integration Token:
- Go to your Medium Security and apps.
- Scroll down to the “Integration tokens” section.
- Click on “Get integration token.”
- Copy the generated token and keep it safe; you’ll need it for your script.
With the token in hand, you’re ready to start coding.
Getting user’s details and publications
Here’s the Python code you’ll be using to interact with the Medium API:
Fetching User Information
When you run the script, it sends a request to Medium’s API to fetch your user information. The response includes details like your user ID, which is required to publish content.
Publishing an Article
Now that you’ve successfully retrieved your user ID from the Medium API, you can move on to publishing an article. The process involves sending a POST request to Medium’s API with the article content and some metadata.
Now you can head over to Medium to check your latest draft. Once you’ve confirmed that everything is formatted correctly, you can go ahead and publish it directly!
2025 Jan Update:
Medium will not be issuing any new integration tokens for our API and will not allow any new integrations.
All existing tokens will continue to work.
上一篇
A Quick Review of SQL Window Functions with Examples
下一篇
Tableau Desktop Public: Try the Free Version for Data Visualization
- Author:Luca Liu
- URL:http://www.blog.luca-liu.com/article/how-to-publish-an-article-to-medium-using-python-and-the-medium-api
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!