웹마스터 팁
page_full_width">

BlogAPI 활용하기
2014.06.29 00:42
BlogAPI를 이용해서 PHP로 생성된 파일을 자동으로 올리고 싶어서 구글링을 해봤지만
확실한 답을 찾지 못하여 이거저거 해보다 나름 방법을 찾아서 남깁니다. ^^;
( 이 방법은 온전한 방법은 아닌거 같습니다. ㅡㅡ;;)
저는 특정 프로그램에서 XML파일을 생성 후 그 내용을 게시판에 매일 자동으로 올리고
싶어서 이용 할려고 찾은 중요부분 입니다.
기본적으로 Xmlrpc.inc 파일과 BlogAPI 애드온 활성화 하셔야 합니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <?php require_once ( 'xmlrpc.inc' ); $g_id = "아이디" ; $g_passwd = "패스워드" ; $GLOBALS [ 'xmlrpc_internalencoding' ] = 'UTF-8' ; function metaWeblog_newPost( $blogid , $title , $content , $tagwords , $categories ) { 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 , "string" ), 'description' => new xmlrpcval( $content , "string" ), 'tagwords' => new xmlrpcval( $tagwords , "string" ), 'categories' => new xmlrpcval( $categories , "string" ) ), "struct" ), new xmlrpcval(true, "boolean" ) // publish ) ); $response = $client ->send( $f ); } $blogid = "아이디" ; //아이디 $title = "제목" ; //제목 $content = "내용" ; //내용 $tagwords = "cate1,cate2" ); $categories = "493" ; //XE slr카테고리 번호 metaWeblog_newPost( $blogid , $title , $content , $tagwords , $categories ); ?> |
'tagwords' => new xmlrpcval($tagwords, "string"),
'categories' => new xmlrpcval($categories, "string")
이 부분은 원래
'tagwords' => new xmlrpcval($tagwords, "array"),
'categories' => new xmlrpcval($categories, "array")
되어야 하는데 배열 변수로 넣어도 되지 않아 삽질을 하다가 BlogAPI 애드온을 변경하는게 좋겠다 싶어서
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | foreach ( $info ->value->struct->member as $val ) { switch ((string) $val ->name) { case 'title' : $obj ->title = (string) $val ->value->string; break ; case 'description' : $obj ->content = (string) $val ->value->string; break ; case 'categories' : $categories = $val ->value-> array ->data->value; $category = (string) $categories [0]->string; if ( $category && $category_list ) { foreach ( $category_list as $category_srl => $category_info ) { if ( $category_info ->title == $category ) $obj ->category_srl = $category_srl ; } } break ; case 'tagwords' : $tags = $val ->value-> array ->data->value; foreach ( $tags as $tag ) { $tag_list [] = (string) $tag ->string; } if ( count ( $tag_list )) $obj ->tags = implode( ',' , $tag_list ); break ; } } |
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | foreach ( $info ->value->struct->member as $val ) { switch ((string) $val ->name) { case 'title' : $obj ->title = (string) $val ->value->string; break ; case 'description' : $obj ->content = (string) $val ->value->string; break ; case 'categories' : $obj ->category_srl = (string) $val ->value->string; break ; case 'tagwords' : $obj ->tags = (string) $val ->value->string; break ; } } |
이렇게 해서 적용한 게시판은 http://nigahae.com/xe/board_dead 입니다.
회원가입을 하셔야 보실 수 있으니... 캡쳐 첨부 합니다.

태그 연관 글
- [2011/11/08] 묻고답하기 blogApi 짧은 주소 사용 불가시 어떻게 해야 될까요? *1
- [2009/11/03] 웹마스터 팁 XE로 API 처리 완전 정복하기(2) *2
- [2009/03/04] 묻고답하기 Windows Live Writer를 이용하여 blogAPI 쓰기 *3