2010-08-10 76 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