2011년 2월 16일 수요일

홈페이지글을 네이버블로그로 포스팅 하기(xmlrpc+php)

include_once "./xmlrpc.inc";
function newPost($title,$description)
{
  $g_blog_url = "https://api.blog.naver.com/xmlrpc";
  $user_id = "네이버블로그아이디";
  $blogid  = "네이버블로그아이디";
  $password = "네이버블로그api번호";
  $publish = true;
  $client = new xmlrpc_client($g_blog_url);
  $client->setSSLVerifyPeer(false); // 기본값은 true 인데,false로 설정하지 않은면 ssl에러남
  $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
  $struct = array(
    'title' => new xmlrpcval($title,"string"),
    'description' => new xmlrpcval($description,"string")
  );
  $f = new xmlrpcmsg("metaWeblog.newPost",
    array(
      new xmlrpcval($blogid,"string"),
      new xmlrpcval($user_id,"string"),
      new xmlrpcval($password,"string"),
      new xmlrpcval($struct,"struct"),
      new xmlrpcval($publish,"boolean")
    )
  );
  $f->request_charset_encoding = 'UTF-8';
  //echo '<pre>'; printf($f); exit;
  return $response = $client->send($f);
}
$return = newPost('test naver rpc',iconv('EUC-KR','UTF-8','TESTTEST..한글'));
ECHO "<pre>";
print_r($return);

댓글 없음:

댓글 쓰기