2010-08-10 33 views
0

我使用XML-RPC成功地使用下面的代碼發佈從Java使用的WordPress XMLRPC

// Hard-coded blog_ID 
int blog_ID = 1; 

// XML-RPC method 
String xmlRpcMethod = "metaWeblog.newPost"; 

// Create our content struct 
... 

// You can specify whether or not you want the blog published 
// immediately 
boolean publish = true; 

try { 
    XmlRpcClient client = new XmlRpcClient(twtr2wp.xmlRpcUrl, false); 

    Object token = client.invoke(xmlRpcMethod, new Object[] { 
      new Integer(blog_ID), 
      twtr2wp.wpUsername, 
      twtr2wp.wpPassword, 
      hmContent, 
      new Boolean(publish) }); 

    // The return is a String containing the postID 
    System.out.println("Posted : " + token.toString()); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

一切工作,除了類別發佈到WordPress在java中。我已經看到,他們需要在一個陣列傳遞,但我還沒有成功通過他們這樣的:

hmContent.put("categories", "[Cat1,Cat2]"); 

誰能幫我找出爲何類不顯示出來?

回答

2

只是在這裏黑暗中猜測,你是否試圖把字符串數組,而不是[Cat1,Cat2]到hmContent?

類似這樣的東西hmContent.put("categories", new String[]{"Cat1", "Cat2"});

+0

謝謝,不知道爲什麼我逃脫了。 – patriot21 2010-08-11 15:07:15