Skip to content
조회 수 12760 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

MetaWeblog API in PHP

Blogger API Tutorial: How To Get Your Blog’s Posts



Your Blog’s ID

Each blog has its own ID from which we can get the posts feed. To get your blog’s id simply open up your dashboard and click “New Post”, your blog id will then be visible in the URL.

blogger blog id

Blog ID in URL

How to Get The Posts With PHP

The URL for a blog’s feed has the following format.

http://www.blogger.com/feeds/blogID/posts/default

If you take this URL, put your blog’s id and paste navigate to it in your browser, you will see that you get an XML response with your posts.

This XML response has an <entry> tag for each one the posts. Inside the entry tag there are other tags such as <title>,<content>, <published> and more. These are the tags we will refer to in our PHP script.

How To Read The Response

Here is a simple PHP script you can use to display your posts’ title, content and published date. If you want to learn about reading XML files in detail check out my post on this subject.
How To Read an XML File From a URL

<?php
$blogID='xxxxxxxxxxx';
$requestURL="http://www.blogger.com/feeds/{$blogID}/posts/default";
$xml=simplexml_load_file($requestURL);
?>
<html>
<body>
<?php
foreach($xml->entry as $post)
{
echo '<div>';
echo '<h2>'.$post->title.'</h2>'; // post title
echo '<p>Published: '.$post->published.'</p>'; // date published
echo '<p>'.$post->content.'</p>'; // post content
echo '</div>';
}
?>
</body>



Implementation of the MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP.

<?php
/**
 * Skeleton file for MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP
 * Requires Keith Deven's XML-RPC Library http://keithdevens.com/software/xmlrpc and store it as xmlrpc.php in the same folder
 * Written by Daniel Lorch, based heavily on Keith Deven's examples on the Blogger API.
 */

require_once dirname(__FILE__) . '/xmlrpc.php';

function metaWeblog_newPost($params) {
  list($blogid, $username, $password, $struct, $publish) = $params;
  $title = $struct['title'];
  $description = $struct['description'];


  // YOUR CODE:
  $post_id = 0; // id of the post you just created


  XMLRPC_response(XMLRPC_prepare((string)$post_id), WEBLOG_XMLRPC_USERAGENT);
}

function metaWeblog_editPost($params) {
  list($postid, $username, $password, $struct, $publish) = $params;


  // YOUR CODE:
  $result = false; // whether or not the action succeeded


  XMLRPC_response(XMLRPC_prepare((boolean)$result), WEBLOG_XMLRPC_USERAGENT);
}

function metaWeblog_getPost($params) {
  list($postid, $username, $password) = $params;
  $post = array();


  // YOUR CODE:
  $post['userId'] = '1';
  $post['dateCreated'] = XMLRPC_convert_timestamp_to_iso8601(time());
  $post['title'] = 'Replace me';
  $post['content'] = 'Replace me, too';
  $post['postid'] = '1';


  XMLRPC_response(XMLRPC_prepare($post), WEBLOG_XMLRPC_USERAGENT);
}

function XMLRPC_method_not_found($methodName) {
  XMLRPC_error("2", "The method you requested, '$methodName', was not found.", WEBLOG_XMLRPC_USERAGENT);
}

$xmlrpc_methods = array(
  'metaWeblog.newPost'  => 'metaWeblog_newPost',
  'metaWeblog.editPost' => 'metaWeblog_editPost',
  'metaWeblog.getPost'  => 'metaWeblog_getPost'
);

$xmlrpc_request = XMLRPC_parse($HTTP_RAW_POST_DATA);
$methodName = XMLRPC_getMethodName($xmlrpc_request);
$params = XMLRPC_getParams($xmlrpc_request);

if(!isset($xmlrpc_methods[$methodName])) {
  XMLRPC_method_not_found($methodName);
} else {
  $xmlrpc_methods[$methodName]($params);
}
?>






로그인 후 댓글쓰기가 가능합니다.

?

List of Articles
번호 분류 제목 날짜 조회 수
597 WindowsTip UEFI 부팅+윈도우 8.1 2015.04.13 6218
596 컴퓨터잡담 [php] 2011.09.02 6233
595 Server 서버 최적화 시키기(APACHE, PHP, MYSQL, XE 압축&캐싱&버퍼) 3 file 2016.03.18 6239
594 컴퓨터잡담 CUBRID 알아보기 2011.06.17 6252
593 [Docs]스프레드시트 구글 스프레드시트 쿼리 사용하기 #3 날짜편 2021.09.26 6265
592 컴퓨터잡담 PHP) 다음 로그인 방식이 바뀌었군. 2012.08.25 6274
591 Server 초간단 웹서버와 파일서버 프로그램 file 2017.12.12 6291
590 WindowsTip 윈도우 Xp에서 사용자 로그온 제거 방법 1 2012.05.18 6292
589 WindowsTip 마이크로소프트 윈도우가 제공하는 기본적인 실행명령어 모음. 2014.12.27 6305
588 컴퓨터잡담 IPv6 몽땅제거 2 2 file 2011.12.26 6309
587 컴퓨터잡담 둥근 모서리 박스 자동 생성 2 2010.07.03 6312
586 컴퓨터잡담 IP공유기 각사별 초기세팅값 2013.04.20 6320
585 컴퓨터잡담 인터넷 통신에서 QOS 의 의미와 사용방법 2013.03.16 6323
584 컴퓨터잡담 마지막 검색 세션이 예상치 못하게 종료되었습니다 3 2011.06.20 6344
583 Excel 엑셀 암호변경 제거 방법 file 2016.09.12 6350
582 [Docs]스프레드시트 구글 드라이브에서 다른 파일 데이터 참조하기 file 2016.08.06 6350
581 컴퓨터잡담 MCU(Micro Controller Unit) 모터제어 등 2 2012.06.19 6352
580 Server APMSETUP7 PHP 업그레이드 2015.06.02 6373
579 컴퓨터잡담 SVCHOST 바이러스 제거하기 2 2012.12.24 6399
578 컴퓨터잡담 ARP(mac spoofing) 바이러스 내용 스크랩 3 file 2012.10.19 6438
Board Pagination Prev 1 ... 15 16 17 18 19 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소