【问题标题】:Posting to wordpress from java using xmlrpc使用 xmlrpc 从 java 发布到 wordpress
【发布时间】:2010-08-10 12:00:00
【问题描述】:

我正在使用 xmlrpc 成功使用以下代码在 java 中发布到 wordpress

    // 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();
}

除类别外,一切正常。我已经看到它们需要在数组中传递,但我没有像这样成功传递它们:

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

谁能帮我弄清楚为什么这些类别没有显示出来?

【问题讨论】:

    标签: java wordpress xml-rpc


    【解决方案1】:

    这里只是在黑暗中猜测,您是否尝试将 String 数组而不是 [Cat1, Cat2] 放入 hmContent ?

    类似hmContent.put("categories", new String[]{"Cat1", "Cat2"});

    【讨论】:

    • 谢谢,不知道为什么我没注意到。
    猜你喜欢
    • 2011-03-04
    • 2023-03-30
    • 1970-01-01
    • 2014-08-22
    • 2011-01-14
    • 1970-01-01
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多