import base64
import requests
"""
# 官方文档: https://developer.wordpress.org/rest-api/
# 接口文档: https://blog.csdn.net/weixin_38633659/article/details/105924225
# 应用程序密码: https://www.vpsgo.com/wordpress-application-passwords.html
注意: 请不要安装其他插件, 比如orange的WordPress REST API Authentication插件, 如果报错, 请尝试关闭其他api插件
"""
api_url = "https://www.yuelili.com/wp-json/wp/v2/posts" # 网站换成你自己的
username = "yueli" # 用户名
application_password = "xxxx xxxx xxxx xxxx xxxx" # 见<应用程序密码>
# 要发布的文章数据, 详情看api
post_data = {
"title": "Post Title",
"slug": "ae",
"content": "post content",
"status": "publish",
"categories": "20,72", # 文章分类id
"tags": "694, 703", # 文章tag id
}
token = base64.b64encode(f"{username}:{application_password}".encode())
header = {"Authorization": "Basic " + token.decode("utf-8")}
response = requests.post(api_url, data=post_data, headers=header)
print(response.json())
"""
{'id': 24578, 'date': '2023-12-26T10:03:02',....
"""
暂无讨论,说说你的看法吧