gpt4 book ai didi

java - 使用 xmlrpc 从 java 发布到 wordpress

转载 作者:行者123 更新时间:2023-12-02 08:30:44 26 4
gpt4 key购买 nike

我使用以下代码成功使用 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]");

谁能帮我找出为什么类别没有显示?

最佳答案

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

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

关于java - 使用 xmlrpc 从 java 发布到 wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3448658/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com