开发者

Tagging Posts via Wordpress XMLRPC

开发者 https://www.devze.com 2022-12-11 04:38 出处:网络
i am trying to publish a new post to a wordpress blog over the XMLRPC API. This works out fine so far, but now i want to add tags to the post. Either开发者_如何学编程 at creation time or afterwards. B

i am trying to publish a new post to a wordpress blog over the XMLRPC API. This works out fine so far, but now i want to add tags to the post. Either开发者_如何学编程 at creation time or afterwards. But i can't find any solutions in the supported APIs.

Any clue on how i can tag new posts via XMLRPC requests?


I hope this code helps

import redstone.xmlrpc.XmlRpcClient;

import java.util.HashMap;

public class wp {


public static void main(String args[]){

    System.out.println("Inciando processo de publicação...");


      // Get command-line arguments into variables
      String sXmlRpcURL = "http://localhost/wordpress/xmlrpc.php";
      String sUsername = "admin";
      String sPassword = "mds123";

      // Hard-coded blog_ID
      int blog_ID = 1;

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

      // We'll hard-code our blog content for now as well
      String sContent = "Hello XML-RPC World! 5";
      String sTitle = "Hello XML-RPC Title 5";

      // Create our content struct
      HashMap hmContent = new HashMap();
      hmContent.put("title", sTitle);
      hmContent.put("description", sContent);
              hmContent.put("mt_keywords", "tag 1, tag 2");


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

      // Try block
      try
      {
        // Create the XML-RPC client

          XmlRpcClient client = new XmlRpcClient( sXmlRpcURL, false );


        // Make our method call
        Object token = client.invoke( sXmlRpcMethod, new Object[] { new Integer( blog_ID ), sUsername, sPassword, hmContent, new Boolean( bPublish ) } );

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

      // Catch exceptions
      catch( Exception e )
      {
        e.printStackTrace( System.err );
      }


    System.out.println("Fim do processo de publicação...");

}




}


Edit mt_keywords property.

0

精彩评论

暂无评论...
验证码 换一张
取 消