2016-03-04 40 views
0

我想使用一個叫做RubyPress的寶石,它允許從ruby使用Wordpress的xml-rpc api。但它總是給我這個錯誤:不能使用RubyPress gem給getaddrinfo:沒有這樣的主機是已知的。 (SocketError)

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頁面。這些類別和標籤不在博客上,是這個原因嗎?

回答

1

host必須是主機名(例如"localhost"在這種特殊情況下,或者說,"google.com"):

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

也許,你可能需要調整path參數最多究竟指向哪裏WP的RPC端點被找到。

+0

是的你是對的,它的工作!非常感謝! –

+0

抱歉再次打擾,它正確提取數據,但現在我似乎無法發佈到博客。我剛剛更新了有問題的代碼。 –

+0

不要感謝它的工作。 –

相關問題