Skip to content

Instantly share code, notes, and snippets.

@openkava
Last active December 20, 2015 09:49
Show Gist options
  • Save openkava/6110626 to your computer and use it in GitHub Desktop.
Save openkava/6110626 to your computer and use it in GitHub Desktop.
require 'xmlrpc/client'
#建立server
begin
server=XMLRPC::Client.new2("http://www.jiangmiao.org/blog/xmlrpc.php")
server.call("wp.getUsersBlogs","admin","blog密码")
rescue
puts $!.message
end
#######################
require 'xmlrpc/client'
# build a post
#Use this for reference - http://codex.wordpress.org/XML-RPC_wp , http://codex.wordpress.org/XML-RPC_WordPress_API
post = {
'post_title' => 'Post Title',
'post_excerpt' => 'Post excerpt',
'post_content' => 'this is Post content'
}
# initialize the connection - Change
connection = XMLRPC::Client.new2('http://www.wordpressapi.com/wordpress3/xmlrpc.php') #Replace your wordpress URL
# make the call to publish a new post
#result = connection.call('metaWeblog.getRecentPosts', 1,'admin','123456') // Get Recent 10 Post
#result = connection.call('wp.getPost', 1,'admin','123456',19) // Get Single Post
#result = connection.call('wp.getPage', 1,'admin','123456',1) // Get Single Page
#result = connection.call('wp.getPages', 1,'admin','123456',10) // Get Pages
#result = connection.call('wp.getPosts', 1,'admin','123456') // Get 10 Posts from wordpress
result = connection.call('wp.getPosts', 1,'admin','123456',1000) // Get 10000 Posts from wordpress
#result = connection.call('wp.newPost', 1,'admin','123456',post) //For New Creating the Post
puts result // Printresult
puts result.length // Printresult
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment