도와주세요..(metaWeblog)
metaWeblog API 를 이용해서 네이버 블로그에 글을 업로드 하는 프로그램을 만들고 있습니다.
일반 글 같은경우 쉽게 되지만,
이미지가 같이 첨부됨에 따라 상당히 복잡해 지는군요..
네이버 같은경우 바로 img 링크를 걸어 올리면 업로드 되지 않기 때문에 (http://naver.com/logo.png 이런식으론 제외)
일반 게시글은 "metaWeblog.newPost" 로 이미지는 "metaWeblog.newMediaObject" 로 올려
값을 받아, img 태그에 삽입해야 하는데
newPost 같은 경우 엄청 잘 올라가지만, "newMediaObject" 같은 경우, 계속 막히네요..
마땅히 메뉴얼 도 없고,, 정보도 부족해서 미칠꺼 같습니다..
고수님들 도움부탁합니다.
-----------
<?
$cBlog = new blog;
$title = "This is a article's title";
$desc = "IT will be the content";
class blog
{
public $g_blog_url;
public $user_id;
public $blogid;
public $password;
public $publish;
function __construct()
{
$this->g_blog_url = "https://api.blog.naver.com/xmlrpc";
$this->user_id = "ID";
$this->blogid = "ID";
$this->password = "API Key";
$this->publish = true;
}
function alert($message)
{
echo $message;
}
function writePost($title, $description)
{
$client = new xmlrpc_client($this->g_blog_url);
$client->setSSLVerifyPeer(false);
$GLOBALS['xmlrpc_internalencoding']='UTF-8';
echo $title;
$img = $this->upload_image("이미지 주소");
$struct = array(
'title' => new xmlrpcval($title, "string"),
'description' => new xmlrpcval($description."<img src=$img>", "string"),
//'categories' => new xmlrpcval($category, "string"),
'tags' => new xmlrpcval('clothing', "string")
);
echo $struct;
$f = new xmlrpcmsg("metaWeblog.newPost",
array(
new xmlrpcval($this->blogid, "string"),
new xmlrpcval($this->user_id, "string"),
new xmlrpcval($this->password, "string"),
new xmlrpcval($struct , "struct"),
new xmlrpcval($this->publish, "boolean")
));
$f->request_charset_encoding = 'UTF-8';
return $response = $client->send($f);
print_r($return);
}
function upload_image($fpath) {
global $api_url, $blog_user, $blog_passwd;
$api_url = $this->g_blog_url;
$blog_user = $this->user_id;
$blog_passwd = $this->password;
$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->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);
if ($r->errno=="0") {
return $r->val['url'];
} else {
echo "There was an error<pre>";
print_r($r);
echo "</pre>";
return null;
}
}
}
$return = $cBlog->writePost($title, $desc);
$re = $b->writePost($title,$desc);
print_r($re);
echo $re;
echo $cBlog->alert("aa");
?>
일반 글 같은경우 쉽게 되지만,
이미지가 같이 첨부됨에 따라 상당히 복잡해 지는군요..
네이버 같은경우 바로 img 링크를 걸어 올리면 업로드 되지 않기 때문에 (http://naver.com/logo.png 이런식으론 제외)
일반 게시글은 "metaWeblog.newPost" 로 이미지는 "metaWeblog.newMediaObject" 로 올려
값을 받아, img 태그에 삽입해야 하는데
newPost 같은 경우 엄청 잘 올라가지만, "newMediaObject" 같은 경우, 계속 막히네요..
마땅히 메뉴얼 도 없고,, 정보도 부족해서 미칠꺼 같습니다..
고수님들 도움부탁합니다.
-----------
<?
$cBlog = new blog;
$title = "This is a article's title";
$desc = "IT will be the content";
class blog
{
public $g_blog_url;
public $user_id;
public $blogid;
public $password;
public $publish;
function __construct()
{
$this->g_blog_url = "https://api.blog.naver.com/xmlrpc";
$this->user_id = "ID";
$this->blogid = "ID";
$this->password = "API Key";
$this->publish = true;
}
function alert($message)
{
echo $message;
}
function writePost($title, $description)
{
$client = new xmlrpc_client($this->g_blog_url);
$client->setSSLVerifyPeer(false);
$GLOBALS['xmlrpc_internalencoding']='UTF-8';
echo $title;
$img = $this->upload_image("이미지 주소");
$struct = array(
'title' => new xmlrpcval($title, "string"),
'description' => new xmlrpcval($description."<img src=$img>", "string"),
//'categories' => new xmlrpcval($category, "string"),
'tags' => new xmlrpcval('clothing', "string")
);
echo $struct;
$f = new xmlrpcmsg("metaWeblog.newPost",
array(
new xmlrpcval($this->blogid, "string"),
new xmlrpcval($this->user_id, "string"),
new xmlrpcval($this->password, "string"),
new xmlrpcval($struct , "struct"),
new xmlrpcval($this->publish, "boolean")
));
$f->request_charset_encoding = 'UTF-8';
return $response = $client->send($f);
print_r($return);
}
function upload_image($fpath) {
global $api_url, $blog_user, $blog_passwd;
$api_url = $this->g_blog_url;
$blog_user = $this->user_id;
$blog_passwd = $this->password;
$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->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);
if ($r->errno=="0") {
return $r->val['url'];
} else {
echo "There was an error<pre>";
print_r($r);
echo "</pre>";
return null;
}
}
}
$return = $cBlog->writePost($title, $desc);
$re = $b->writePost($title,$desc);
print_r($re);
echo $re;
echo $cBlog->alert("aa");
?>
댓글 2개
돼지코구뇽
11년 전
자신의 사이트에 글작성시 네이버 블로그에 글이 자동으로 써지긴하는데
제목,내용,링크까지는 1초안에 올라가는데;
이미지경우 저도 ㅠㅠ 해결이....
제목,내용,링크까지는 1초안에 올라가는데;
이미지경우 저도 ㅠㅠ 해결이....
jfascas
11년 전
해결했어요 ㅎㅎㅎㅎㅎ
게시판 목록
그누4 질문답변
그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기
기존 게시물은 열람만 가능합니다.
기존 게시물은 열람만 가능합니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 66514 | 11년 전 | 2127 | ||
| 66513 | 11년 전 | 4476 | ||
| 66512 | 11년 전 | 4140 | ||
| 66511 | 11년 전 | 2409 | ||
| 66510 | 11년 전 | 3022 | ||
| 66509 |
반갑습니다요
|
11년 전 | 2885 | |
| 66508 |
|
11년 전 | 3474 | |
| 66507 |
자동차방향제
|
11년 전 | 2931 | |
| 66506 |
구라대마왕
|
11년 전 | 2703 | |
| 66505 | 11년 전 | 2780 | ||
| 66504 | 11년 전 | 3110 | ||
| 66503 |
착한아이민이
|
11년 전 | 3296 | |
| 66502 | 11년 전 | 2712 | ||
| 66501 |
착한아이민이
|
11년 전 | 2560 | |
| 66500 |
canth
|
11년 전 | 3289 | |
| 66499 |
한번잘해보자
|
11년 전 | 4226 | |
| 66498 | 11년 전 | 2859 | ||
| 66497 |
xargs
|
11년 전 | 2545 | |
| 66496 |
aisru
|
11년 전 | 2630 | |
| 66495 |
alexseo
|
11년 전 | 2732 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기