如何使用REST API将帖子发送到WordPress

问题描述 投票:0回答:1

[我有一个可以使用REST API将帖子发送到WordPress网站的脚本,现在我需要发送具有更多功能的帖子,首先是具有帖子类型的帖子,其次是调用并设置一些自定义字段的值

这是我的python代码:

auth = 'Basic ' + str(base64.b64encode(b'jason:WdOb zgW5 Oq5I LhT3 9Gkw tiJg'), 'utf-8')
                headers = {'Authorization': auth}
                body = {'title': pointer , 'content': myresult_pointer[0] ,'categories':categories_id,'status':"publish",'comment_status':"open"}
                r = requests.post('http://aaa.com/wp-json/wp/v2/posts', headers=headers, data=body)

和帖子类型的URL(粗体):

http://aaa.com/wp-admin/post-new.phppost_type = movies

另一件事是当我运行代码时,它返回此:

{'x-powered-by': 'PHP/7.2.22', 'content-type': 'application/json; charset=UTF-8', 'x-robots-tag': 'noindex', 'link': '<http://aaa.com/wp-json/>; rel="https://api.w.org/"', 'x-content-type-options': 'nosniff', 'access-control-expose-headers': 'X-WP-Total, X-WP-TotalPages', 'access-control-allow-headers': 'Authorization, Content-Type', 'content-length': '113', 'date': 'Fri, 25 Oct 2019 20:04:58 GMT', 'referrer-policy': 'no-referrer-when-downgrade', 'connection': 'close'}

python wordpress rest wordpress-rest-api
1个回答
0
投票

[如果您只需要创建具有自定义帖子类型的帖子,则WordPress拥有自己的REST API来创建帖子。请参阅here

© www.soinside.com 2019 - 2024. All rights reserved.