[wordpress] 通过restapi以及python发布文章

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',....
"""

给TA充电
共{{data.count}}人
人已充电
wordpress

[wordpress]B2主题美化 子专题设置

2023-6-28 16:11:58

wordpress

[nginx]跨文件夹访问资源

2024-2-23 18:32:52

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
今日签到
搜索