如何使用 REST API 将 post 发送到 WordPress
How to send post to WordPress with REST API
我有一个脚本,可以使用 REST API 将 post 发送到 WordPress 网站,现在我需要发送 post 更多功能,首先制作 post具有 post 类型,第二个是调用并将值设置为某些自定义字段
这是我的 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)
和post类型的url(粗体部分):
http://aaa.com/wp-admin/post-new.php?post_type=电影
另一件事是当我 运行 代码时 return 这个:
{'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'}
我有一个脚本,可以使用 REST API 将 post 发送到 WordPress 网站,现在我需要发送 post 更多功能,首先制作 post具有 post 类型,第二个是调用并将值设置为某些自定义字段
这是我的 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)
和post类型的url(粗体部分):
http://aaa.com/wp-admin/post-new.php?post_type=电影
另一件事是当我 运行 代码时 return 这个:
{'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'}