[MetaWeblog] Www.Xmlrpc.Com/MetaWeblogApi XML-RPC (자료수집중) Http://Sitehis.Com/Db_talk_369 > Windows

본문 바로가기

Windows

[노하우] [MetaWeblog] Www.Xmlrpc.Com/MetaWeblogApi XML-RPC (자료수집중) Http://Siteh…

회원사진
하나를하더라도최선을
2019-10-01 14:19 6,830 0
  • - 첨부파일 : 네이버블로그글쓰기API스팩문서20100420.docx (248.6K) - 다운로드
  • - 첨부파일 : aspxmlrpc.zip (23.1K) - 다운로드

본문



출처 ::: https://www.sitehis.com/spb3/sboard3/read.php?db=talk&cateuid=8&uid=369&mobileagent=yes


- 첨부파일 : 네이버블로그글쓰기API스팩문서(20100420).docx (크기: 254,555 bytes)

metaWeblogApi XML-RPC를 통해서 네이버 블로그에도 글을 올릴 수 있다.

관련 정보를 수집하여 봅니다.

공식 RFC : http://www.xmlrpc.com/metaWeblogApi

샘플 소스

네이버

xmlrpc 서버 테스트

명령어 (출처 : http://sangogi.com/2656795 )

  • metaWeblog.newPost (blogid, username, password, struct, publish)
  • metaWeblog.editPost (postid, username, password, struct, publish)
  • metaWeblog.getPost (postid, username, password)
  • metaWeblog.newMediaObject (blogid, username, password, struct)
  • metaWeblog.getCategories (blogid, username, password)
  • metaWeblog.getRecentPosts (blogid, username, password, numberOfPosts)
     


 

<?
//환경설정
$q_blogApiUrl = array(
"tistory"=>"http://blog.qnibus.com/api",
"naver"=>"https://api.blog.naver.com/xmlrpc",
"egloos"=>"https://rpc.egloos.com/rpc1",
"wordpress"=>"http://qnibus.wordpress.com/xmlrpc.php"
);
$q_blogId = array(
"tistory"=>"123456",
"naver"=>"blogid",
"egloos"=>"blogid",
"wordpress"=>"blogid"
);
$q_userName = array(
"tistory"=>"blog@example.com",
"naver"=>"id",
"egloos"=>"blog@example.com",
"wordpress"=>"id"
);
$q_password = array(
"tistory"=>"password",
"naver"=>"api_key",
"egloos"=>"api_key",
"wordpress"=>"password"
);
require_once 'lib/xmlrpc/lib/xmlrpc.inc';
$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8'; //한글 출력 가능케 함 반드시 넣어야 함 안넣으면 오류발생
$q = $_GET['q'] ? $_GET['q'] : 'naver';
//카테고리 정보 추출 시작
$client = new xmlrpc_client($q_blogApiUrl[$q]);
$message = new xmlrpcmsg("metaWeblog.getCategories",
array(
new xmlrpcval($q_blogId[$q], "string"),
new xmlrpcval($q_userName[$q], "string"),
new xmlrpcval($q_password[$q], "string"),
)
);
$message->request_charset_encoding = 'UTF-8';
$response = $client->send($message);
$value = $response->value(); //카테고리 struct 반환
for($i=0; $i<$value->arraysize(); $i++) $categories[$i] = $value->arraymem($i)->me['struct']['title']->me['string']; //카테고리 타이틀 배열로 생성
natsort($categories); //자연어 정렬
?>
<html>
<head>
<title>원격발행</title>
</head>
<body>
<h1>metaWeblog API</h1>
<ul>
<li><a href="./?q=naver">네이버</a></li>
<li><a href="./?q=tistory">티스토리</a></li>
<li><a href="./?q=egloos">이글루스</a></li>
<li><a href="./?q=wordpress">워드프레스</a></li>
</ul>
<form method="post" enctype="multipart/form-data">
<fieldset>
<legend>newPost Publish</legend>
<input type="hidden" name="q" value="<?php echo $q?>" />
<p>
<label>Title</label>
<input type="text" name="title" size="30" />
</p>
<p>
<label>Category</label>
<select name="categories">
<?php foreach($categories as $val):?>
<option value="<?php echo $val?>"><?php echo $val?></option>
<?php endforeach?>
</select>
</p>
<p>
<label>Description</label>
<textarea name="description" cols="50" rows="5"></textarea>
</p>
<p>
<label>Tags</label>
<input type="text" name="keywords" value="PhotoShake!" />
</p>
<p>
<label>File</label>
<input type="file" name="upload" />
</p>
<p>
<input type="submit" value="submit" />
</p>
</fieldset>
</form>
</body>
</html>
 
<?
//환경설정 (공동으로 사용하는 파일이니 xmlrpc.inc나 config.php로 파일 만들어 include 시켜서 사용하세요 한눈에 보여드리려고 풀어헤쳤습니다.
//반드시 환경설정부는 자신의 블로그 관리에서 확인하신후 정보를 변경하셔야 정상 출력합니다.
$q_blogApiUrl = array(
"tistory"=>"http://blog.qnibus.com/api",
"naver"=>"https://api.blog.naver.com/xmlrpc",
"egloos"=>"https://rpc.egloos.com/rpc1",
"wordpress"=>"http://qnibus.wordpress.com/xmlrpc.php"
);
$q_blogId = array(
"tistory"=>"123456",
"naver"=>"blogid",
"egloos"=>"blogid",
"wordpress"=>"blogid"
);
$q_userName = array(
"tistory"=>"blog@example.com",
"naver"=>"id",
"egloos"=>"blog@example.com",
"wordpress"=>"id"
);
$q_password = array(
"tistory"=>"password",
"naver"=>"api_key",
"egloos"=>"api_key",
"wordpress"=>"password"
);
require_once 'xmlrpc/lib/xmlrpc.inc';
$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
// 파일 업로드
if (!empty($_FILES['upload']['name']))
{
$tempFile = $_FILES['upload']['tmp_name'];
$fileName = $_FILES['upload']['name'];
$fileType = $_FILES['upload']['type'];
// 파일 바이너리 데이터 가져오기
$fp=fopen($tempFile, "rb");
if (!$fp) return null; // file open failure !!
while( !feof($fp))
{
$filedescription .= fread( $fp, 1024); // 1024 is the server compatible buffer size
flush();
@ob_flush();
}
fclose($fp);
$client = new xmlrpc_client($q_blogApiUrl[$q]);
$newMediaObject = new xmlrpcmsg("metaWeblog.newMediaObject",
array(
new xmlrpcval($q_blogId[$q], "string"),
new xmlrpcval($q_userName[$q], "string"),
new xmlrpcval($q_password[$q], "string"),
new xmlrpcval(
array(
'name'  => new xmlrpcval($fileName, "string"),
'type'  => new xmlrpcval($fileType, "string"),
'bits' => new xmlrpcval($filedescription, "base64"), //파일 바이너리 값
), "struct")
)
);
$newMediaObject->request_charset_encoding = 'UTF-8';
$tempResponse = $client->send($newMediaObject);
$uploadFileName = $tempResponse->value()->me['struct']['url']->me['string'];
$uploadFileSize = getimagesize($tempFile);
$description = '<img src="'.$uploadFileName.'" '.$uploadFileSize[3].' /><br />'.$description.'<p>'.$_SERVER['REMOTE_ADDR'].'</p>';
}
$content = array(
'title'   => new xmlrpcval($title, "string"),
'description'   => new xmlrpcval($description, "string"),
        'dateCreated'  => new xmlrpcval(date("Ymd")."T".date("H:i:s"), "dateTime.iso8601"),
'categories' => new XMLRPCval(array(new XMLRPCval($categories,"string")), "array"),
($q=='naver') ? 'tags' : 'mt_keywords' => new xmlrpcval($keywords),
);
$client = new xmlrpc_client($q_blogApiUrl[$q]);
$message = new xmlrpcmsg("metaWeblog.newPost",
array(
new xmlrpcval($q_blogId[$q], "string"),
new xmlrpcval($q_userName[$q], "string"),
new xmlrpcval($q_password[$q], "string"),
new xmlrpcval($content, "struct"),
new xmlrpcval(true, "boolean")
)
);
$message->request_charset_encoding = 'UTF-8';
$response = $client->send($message);
$value = $response->value();
$postno = $value->scalarval(); // 발행한 결과로 블로그의 포스트 넘버를 반환합니다.
//디버그 확인
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
if(!$response->faultCode()) echo "성공적으로 발행되었습니다.";
else echo htmlspecialchars($response->faultString()); //에러 메시지 출력
 

 include("xmlrpc.inc");
 $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';


 $api_url = "https://api.blog.naver.com/xmlrpc";
 $blog_user = "네이버ID";
 $blog_passwd = "API 연결암호";


 

 function upload_image($fpath) {
  global $api_url, $blog_user, $blog_passwd;
 
  $imgbit = file_get_contents($fpath, FILE_BINARY);
  $img = new xmlrpcval(
   array (
    'bits' => new xmlrpcval($imgbit, 'base64'),
    'type' => new xmlrpcval('image/jpeg', 'string'),
    'name' => new xmlrpcval(basename($fpath), 'string')
   ), 'struct');

  $c = new xmlrpc_client($api_url);
//  $c->debug = true; // Uncomment this line for debugging info
  $c->setSSLVerifyPeer(false);

  $x = new xmlrpcmsg("metaWeblog.newMediaObject");
  $x->addParam(new xmlrpcval($blog_user, 'string'));
  $x->addParam(new xmlrpcval($blog_user, 'string'));
  $x->addParam(new xmlrpcval($blog_passwd, 'string'));
  $x->addParam($img);
 
  $c->return_type = 'phpvals';
  $r =$c->send($x, 3, 'https');
  if ($r->errno=="0") {
      return $r->val['url'];
  } else {
      echo "<br>There was an error<pre>";
      print_r($r);
      echo "</pre>";
      return null;
  }
 
 } // upload_image


 function new_post($subj, $content) {
  global $api_url, $blog_user, $blog_passwd;
 
  $c = new xmlrpc_client($api_url);
//  $c->debug = true; // Uncomment this line for debugging info
  $c->setSSLVerifyPeer(false);
 
  $post = new xmlrpcval(
   array (
    'title' => new xmlrpcval($subj, 'string'),
    'description' => new xmlrpcval($content, 'string')
   ), 'struct');
 
  $x = new xmlrpcmsg("metaWeblog.newPost");
  $x->addParam(new xmlrpcval($blog_user, 'string'));
  $x->addParam(new xmlrpcval($blog_user, 'string'));
  $x->addParam(new xmlrpcval($blog_passwd, 'string'));
  $x->addParam($post);
  $x->addParam(new xmlrpcval(true, 'boolean'));
  $x->request_charset_encoding = "UTF-8";
 
  $c->return_type = 'phpvals';
  $r =$c->send($x, 3, 'https');
  if ($r->errno=="0") {
   $post_url = "http://blog.naver.com/$blog_user/".$r->val;
      return $post_url;
  } else {
      echo "<br>There was an error<pre>";
      print_r($r);
      echo "</pre>";
      return null;
  }
 } // new_post

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색