0

我正在尝试使用一个名为RubyPress的 gem ,它允许使用来自 ruby​​ 的 Wordpress 的 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的 gem 进行正常连接,但 ruby​​press 似乎不起作用。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']
                                          }
                         }
            ) 

注意:这是来自 ruby​​press github 页面。那些类别和标签没有出现在博客上,是这个原因吗?

4

1 回答 1

1

host必须是主机名(例如"localhost",在这种特殊情况下,或者说,"google.com"):

require 'rubypress'
wp = Rubypress::Client.new(host: "localhost",
                           username: "admin",
                           password: "admin",
                           path: "/wordpress/xmlrpc.php")

可能,您可能需要调整path参数以准确指向要找到 WP 的 RPC 端点的位置。

于 2016-03-04T11:29:52.117 回答