http://pear.php.net/package/Services_Blogging/download/0.2.3/
から、ソースを落として読んでみました。
XML-RPC のメソッドを隠してるあたりが、Blogging/Driver/MetaWeblog.php ですが、
実装されてるメソッドが、以下の五つだけです。
wp.newCategory のように、上記以外のメソッドは、残念ながら Services_Blogging では利用できません。
カテゴリの新規登録のエッセンスを書きだすと、こんな感じになると思います。
<?php require_once("XML/RPC.php"); $GLOBALS['XML_RPC_defencoding'] = "UTF-8"; $host = "サイトのURL"; $xmlrpc_path = "/xmlrpc.php"; $blog_id = ブログID; $user = ユーザー名; $pass = パスワード; $category_name = カテゴリ名; $category_slug = カテゴリスラッグ; $category_parent_id = 親のID; $category_description = カテゴリの説明; $client = new XML_RPC_client($xmlrpc_path, $host, 80); $blog_id = new XML_RPC_Value($blog_id, 'int'); $user = new XML_RPC_Value($user, 'string'); $pass = new XML_RPC_Value($pass, 'string'); $category = new XML_RPC_Value( array( 'name' => new XML_RPC_Value($category_name, 'string'), 'slug' => new XML_RPC_Value($category_slug, 'string'), 'parent_id' => new XML_RPC_Value($category_parent_id, 'int'), 'description' => new XML_RPC_Value($category_description, 'string') ), 'struct'); $request = new XML_RPC_Message( 'wp.newCategory', array($blog_id, $user, $pass, $category) ); $response = $client->send($request); ?>
メソッド名と、パラメータの型や意味は、↓で調べます。
http://codex.wordpress.org/XML-RPC_wp
後、Services_Blogging じゃありませんが、XML_RPC を使うライブラリを書いている人がいました。
http://shoji.blog1.fc2.com/blog-entry-179.html
でも、blogger メンバーが構築されて無いような気がするので、このままでは使えないような気がします。
▽3
●
rouge_2008 ●50ポイント ベストアンサー |
既に回答されていますが、MetaWeblog APIではカテゴリーの作成が出来ませんので、新規カテゴリーの作成だけWordPress APIを使用してはいかがでしょうか?
http://www.moonmile.net/blog/archives/1416
各APIの対応状況は上記ページの通りですが、新バージョンの3.2.xの場合は、「wp-includes/class-wp-xmlrpc-server.php」で確認できます。
function __construct() {
$this->methods = array(
// WordPress API
'wp.getUsersBlogs' => 'this:wp_getUsersBlogs',
'wp.getPage' => 'this:wp_getPage',
'wp.getPages' => 'this:wp_getPages',
'wp.newPage' => 'this:wp_newPage',
'wp.deletePage' => 'this:wp_deletePage',
'wp.editPage' => 'this:wp_editPage',
'wp.getPageList' => 'this:wp_getPageList',
'wp.getAuthors' => 'this:wp_getAuthors',
'wp.getCategories' => 'this:mw_getCategories', // Alias
'wp.getTags' => 'this:wp_getTags',
'wp.newCategory' => 'this:wp_newCategory',
'wp.deleteCategory' => 'this:wp_deleteCategory',
'wp.suggestCategories' => 'this:wp_suggestCategories',
'wp.uploadFile' => 'this:mw_newMediaObject', // Alias
'wp.getCommentCount' => 'this:wp_getCommentCount',
'wp.getPostStatusList' => 'this:wp_getPostStatusList',
'wp.getPageStatusList' => 'this:wp_getPageStatusList',
'wp.getPageTemplates' => 'this:wp_getPageTemplates',
'wp.getOptions' => 'this:wp_getOptions',
'wp.setOptions' => 'this:wp_setOptions',
'wp.getComment' => 'this:wp_getComment',
'wp.getComments' => 'this:wp_getComments',
'wp.deleteComment' => 'this:wp_deleteComment',
'wp.editComment' => 'this:wp_editComment',
'wp.newComment' => 'this:wp_newComment',
'wp.getCommentStatusList' => 'this:wp_getCommentStatusList',
'wp.getMediaItem' => 'this:wp_getMediaItem',
'wp.getMediaLibrary' => 'this:wp_getMediaLibrary',
'wp.getPostFormats' => 'this:wp_getPostFormats',
// Blogger API
'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
'blogger.getUserInfo' => 'this:blogger_getUserInfo',
'blogger.getPost' => 'this:blogger_getPost',
'blogger.getRecentPosts' => 'this:blogger_getRecentPosts',
'blogger.getTemplate' => 'this:blogger_getTemplate',
'blogger.setTemplate' => 'this:blogger_setTemplate',
'blogger.newPost' => 'this:blogger_newPost',
'blogger.editPost' => 'this:blogger_editPost',
'blogger.deletePost' => 'this:blogger_deletePost',
// MetaWeblog API (with MT extensions to structs)
'metaWeblog.newPost' => 'this:mw_newPost',
'metaWeblog.editPost' => 'this:mw_editPost',
'metaWeblog.getPost' => 'this:mw_getPost',
'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts',
'metaWeblog.getCategories' => 'this:mw_getCategories',
'metaWeblog.newMediaObject' => 'this:mw_newMediaObject',
// MetaWeblog API aliases for Blogger API
// see http://www.xmlrpc.com/stories/storyReader$2460
'metaWeblog.deletePost' => 'this:blogger_deletePost',
'metaWeblog.getTemplate' => 'this:blogger_getTemplate',
'metaWeblog.setTemplate' => 'this:blogger_setTemplate',
'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs',
// MovableType API
'mt.getCategoryList' => 'this:mt_getCategoryList',
'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles',
'mt.getPostCategories' => 'this:mt_getPostCategories',
'mt.setPostCategories' => 'this:mt_setPostCategories',
'mt.supportedMethods' => 'this:mt_supportedMethods',
'mt.supportedTextFilters' => 'this:mt_supportedTextFilters',
'mt.getTrackbackPings' => 'this:mt_getTrackbackPings',
'mt.publishPost' => 'this:mt_publishPost',
// PingBack
'pingback.ping' => 'this:pingback_ping',
'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks',
'demo.sayHello' => 'this:sayHello',
'demo.addTwoNumbers' => 'this:addTwoNumbers'
);
・カテゴリ作成のコード
http://codex.wordpress.org/XML-RPC_wp#wp.newCategory
require_once("IXR_Library.php"); $rpc = new IXR_Client("http://blog.example.com/xmlrpc.php"); $status = $rpc->query( "wp.newCategory", "1", "UserName", // username "Password", // password array( "name"=>"カテゴリ1", "slug"=>"category1", "parent_id"=>"", // 親カテゴリのID "description"=>"カテゴリ1について" //カテゴリの説明 ) ); $data = $rpc->getResponse( ); //print_r( $data ); 出力確認 //上記の処理以降に、MetaWeblog APIによる投稿のコードを記述します。
「IXR_Library.php」は次のページでダウンロードできます。