Hello Python-xlmrpc POST
—–It is posted by python-wordpress-xmlrpc 2.2. Good ——
參考網頁: python-wordpress-xmlrpc 2.2 documentation
非常簡單,先以 easy_install python-wordpress-xmlrpc 指令安裝。
然後直接用就可以了,Code 如下:
# -*- coding: utf-8 -*- from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods.posts import GetPosts, NewPost from wordpress_xmlrpc.methods.users import GetUserInfo wp = Client('http://您的網址與xmlrpc位置', '帳號', '密碼') post = WordPressPost() post.title = '標題' post.content = '內文' post.terms_names = {'category': ['英文分類標籤']} post.post_status='publish' ### 沒有最後這行 post.post_status 的話 ## ### 預設狀態是「草稿」,要加這行才可以直接發表 ## wp.call(NewPost(post))
其他詳細的PO文參數可以參考 WordPressPost 的內容:
class WordPressPost(WordPressBase): definition = { 'id': 'post_id', 'user': 'post_author', 'date': DateTimeFieldMap('post_date_gmt'), 'date_modified': DateTimeFieldMap('post_modified_gmt'), 'slug': 'post_name', 'post_status': 'post_status', 'title': FieldMap('post_title', default='Untitled'), 'content': 'post_content', 'excerpt': 'post_excerpt', 'link': 'link', 'comment_status': 'comment_status', 'ping_status': 'comment_status', 'terms': TermsListFieldMap(WordPressTerm, 'terms'), 'terms_names': 'terms_names', 'custom_fields': 'custom_fields', 'enclosure': 'enclosure', 'password': 'post_password', 'post_format': 'post_format', 'thumbnail': 'post_thumbnail', 'sticky': 'sticky', 'post_type': FieldMap('post_type', default='post'), 'parent_id': 'post_parent', 'menu_order': IntegerFieldMap('menu_order'), 'guid': 'guid', 'mime_type': 'post_mime_type', }