我正在尝试使用名为RubyPress的宝石,它允许使用Wordpress'来自ruby的xml-rpc api。但它总是给我这个错误:
getaddrinfo: No such host is known. (SocketError)
这是我的代码:
require 'rubypress'
wp = Rubypress::Client.new(:host => "localhost/wordpress",
:username => "admin",
:password => "admin")
p wp.getOptions
我可以使用另一个名为wp_rpc的宝石连接正常,但rubypress似乎无法正常工作。 Rubypress似乎得到维护,所以我想使用它,它似乎也有更多的功能。
此外,即使我尝试连接到真实网站,它也会出现403错误,这很奇怪。
我在Windows 7上使用XAMPP运行服务器。如何让它运行?
更新: 这是我用于发布的代码,现在它似乎没有发布。不知道我哪里出错了。
wp.newPost( :blog_id => 0, # 0 unless using WP Multi-Site, then use the blog id
:content => {
:post_status => "publish",
:post_date => Time.now,
:post_content => "This is the body",
:post_title => "RubyPress is the best!",
:post_name => "/rubypress-is-the-best",
:post_author => 1, # 1 if there is only the admin user, otherwise the user's id
:terms_names => {
:category => ['Category One','Category Two','Category Three'],
:post_tag => ['Tag One','Tag Two', 'Tag Three']
}
}
)
注意:这是来自rubypress github页面。博客上没有这些类别和标签,原因是什么?
答案 0 :(得分:1)
host
必须是主机名(例如,在此特定情况下为"localhost"
,或者说,"google.com"
):
require 'rubypress'
wp = Rubypress::Client.new(host: "localhost",
username: "admin",
password: "admin",
path: "/wordpress/xmlrpc.php")
或许,您可能需要将path
参数调整为精确指向WP的RPC终点的位置。