'PHP RPCXML'에 해당되는 글 1건

  1. 2008/01/02 How to post blog content by metaweblog API ? (2)
2008/01/02 15:59

How to post blog content by metaweblog API ?

"metaweblog API" is very usefull when you want to post content automatically or periodically. For example, if you are planning to release news letter by collecting the recent articles on your blog, this is very useful tool.

The below module is available with tistory blog. You can also try to other blogs supporting metaweblog API. As I mentioned in other article, Microsoft Windows Live Writer is also using this kind of technology to post blog stuffs.

In order to post content by metaweblog API, you need xmlrpc.inc module on the same working directory.

<?php
//requires xmlrpc.inc from http://phpxmlrpc.sourceforge.net/
require_once('xmlrpc.inc');

$g_blog_url = "http://demoblog.kurapa.com/api/";
$g_id = "kurapa@kurapa.com";
$g_passwd = "*****";

$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';

function metaWeblog_newPost( $blogid, $title, $content, $tags, $category="")
{
  global $g_id;
  global $g_passwd;
  global $g_blog_url;
 
  $client = new xmlrpc_client( "{$g_blog_url}");
  $f = new xmlrpcmsg("metaWeblog.newPost", // metaWeblog.newPost method
    array(
      new xmlrpcval("{$blogid}", "string"), // blogid.
      new xmlrpcval($g_id, "string"), // user ID.
      new xmlrpcval($g_passwd, "string"), // password
      new xmlrpcval( // body
          array(
            'title'        => new xmlrpcval($title, "base64"),
            'description'    => new xmlrpcval($content, "base64"),
            'category'    => new xmlrpcval($category, "base64"),
            'mt_keywords' => new xmlrpcval($tags, "base64")
        ), "struct"),
      new xmlrpcval(true, "boolean") // publish
    )
  );

  $f->request_charset_encoding = 'UTF-8';

  $response = $client->send($f);
}

metaWeblog_newPost( 0, "test title", "content should be added here", "tag1,tag2");

?>

Trackback 0 Comment 2