« 画像サイズ変更 convert | メイン | XML処理 »
2008年04月24日
ブログと対話できる
XML-RPC APIを使ってブログと対話できっぽい。
http://www.sixapart.jp/movabletype/manual/3.2/mtmanual_programmatic.html
以下 焼きそばソース例
--------------------------------------------------------------
require_once("XML/RPC.php"); //XML-RPC package 読み込み
$GLOBALS['XML_RPC_defencoding'] = "UTF-8";
//XML-RPCインタフェース、ユーザ定義
$mt_host = "www.saburo.org";
$mt_xmlrpc_path = "/shell/mt-xmlrpc.cgi";
$port = 80;
$mt_user = "hogehogeo";
$mt_xmlrpc_passwd = "hogehogeo";
//クライアントの作成
$myClient = new XML_RPC_client( $mt_xmlrpc_path, $mt_host, $port );
$appkey = new XML_RPC_Value( '', 'string' );
$username = new XML_RPC_Value( $mt_user, 'string' );
$passwd = new XML_RPC_Value( $mt_xmlrpc_passwd, 'string' );
//メッセージ作成
$myMessage = new XML_RPC_Message(
'blogger.getUsersBlogs',
array($appkey, $username, $passwd) );
//メッセージ送信
$myResponse = $myClient->send($myMessage);
//レスポンス受信後の処理
if( !$myResponse ){
exit('Could not connect to the server.');
}else if($myResponse->faultCode() ){
exit('XML-RPC fault ('.$myResponse->faultCode().'): '
.$myResponse->faultstring());
}
//レスポンスへのfunction array_convEnc($a)適用
$myBlogs = array_map( 'array_convEnc', XML_RPC_decode( $myResponse->value() ) );
//出力
print_r($myBlogs);
function array_convEnc($a)
{
if( is_array($a) ){ return array_map( 'array_convEnc', $a ); }
return mb_convert_encoding(
$a, mb_internal_encoding(),
$GLOBALS['XML_RPC_defencoding'] );
これを色々組み合わせれば 自動ブログ記事生成機能が完成(予定
投稿者 muuming : 2008年04月24日 17:17