wordpress 使用api发布文章

1.安装插件

在/wp-content/plugins/目录执行以下命令

$ sudo git clone https://github.com/WP-API/Basic-Auth.git

2.Python脚本

import requests

url = 'http://www.ziyuanwang.online/wp-json/wp/v2/posts'

user = 'admin'

password = 'xxxxx'

headers = {

    'Content-Type': 'application/json',

}

post = {

    'title': 'Hello World',

    'status': 'publish',

    'content': 'This is my first post published from Python.',

    'author': '1',  # Assuming '1' is your user ID in WordPress

}

response = requests.post(url, json=post, headers=headers, auth=(user, password))


if response.status_code == 201:

    print("Post published successfully")

else:

    print("Failed to publish post")
    
 致谢   
https://blog.csdn.net/cunjie3951/article/details/106923078?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7EPaidSort-1-106923078-blog-78706423.235%5Ev43%5Epc_blog_bottom_relevance_base6&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7EPaidSort-1-106923078-blog-78706423.235%5Ev43%5Epc_blog_bottom_relevance_base6&utm_relevant_index=1

相关推荐

  1. wordpress 使用api发布文章

    2024-06-08 10:46:02       29 阅读
  2. WordPress定时发布文章失败的原因及解决办法

    2024-06-08 10:46:02       53 阅读
  3. WordPress发布文件随机设置作者昵称信息

    2024-06-08 10:46:02       57 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-08 10:46:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-08 10:46:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-08 10:46:02       87 阅读
  4. Python语言-面向对象

    2024-06-08 10:46:02       96 阅读

热门阅读

  1. zookeeper节点启动的主要逻辑

    2024-06-08 10:46:02       22 阅读
  2. Linux socket非阻塞发送

    2024-06-08 10:46:02       21 阅读
  3. 【C语言进阶】--- 字符串函数与内存函数

    2024-06-08 10:46:02       27 阅读
  4. C++自定义list实现

    2024-06-08 10:46:02       25 阅读
  5. 常见名词之时间戳

    2024-06-08 10:46:02       29 阅读
  6. 第49集《摄大乘论》

    2024-06-08 10:46:02       20 阅读
  7. 列举Spring的IoC和AOP的特点

    2024-06-08 10:46:02       23 阅读
  8. #06 掌握Stable Diffusion:自定义模型训练步骤

    2024-06-08 10:46:02       28 阅读
  9. 「前端+鸿蒙」鸿蒙应用开发预览&模拟器运行

    2024-06-08 10:46:02       28 阅读
  10. SpringEvent事件发布&订阅Demo

    2024-06-08 10:46:02       24 阅读
  11. Dart语言中mixins的使用

    2024-06-08 10:46:02       26 阅读