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
번호 분류 제목 날짜 조회 수
157 컴퓨터잡담 Windows Movie Maker 2.1 다운로드 2 2 file 2010.09.11 22457
156 컴퓨터잡담 XP윈도우가 버벅 거릴때 시스템 파일 복구하기 1 2010.09.11 11273
155 컴퓨터잡담 동영상 제작프로그램, 파워디렉터(POWER DIRECTOR) 1 2 2010.09.10 20214
154 컴퓨터잡담 이전 버전의 Office로 Office 2007 파일을 여는 방법 1 2010.09.04 11301
153 컴퓨터잡담 Excel에서 틀 고정 방법 2010.09.04 18628
152 컴퓨터잡담 아파치서버에서 시작시 무엇을 불러들이나? httpd -l 1 2 2010.09.04 9780
151 컴퓨터잡담 [악성코드제거] 가짜백신에 속지말고 MS정품을 이용하자. 2010.09.02 10318
150 컴퓨터잡담 무선랜 비밀번호 모음 3 2010.08.26 16895
149 컴퓨터잡담 [악성코드] 컴퓨터가 주기적으로 꺼지는 현상 2 2010.08.24 12217
148 컴퓨터잡담 hMailServer - 설치시 주의 핵심사항 1 2010.08.24 103067
147 컴퓨터잡담 [윈도우 웹서버] hmailserver 1 1 2010.08.22 23389
146 컴퓨터잡담 부팅시마다 체크디스크 실행되는 경우 설정방법 2010.08.21 26563
145 컴퓨터잡담 Tips N Tricks Process Listing - Using third party DLL! 2010.08.14 20424
144 컴퓨터잡담 [autohotkey] 시스템 레지스트리 수정, 삭제 2010.08.14 8486
143 컴퓨터잡담 [autohotkey] 시스템 레지스트리 수정, 삭제 1 3 2010.08.14 8062
142 컴퓨터잡담 [잦은오류해결] 오류발생을 알려주는 drwtsn32.exe 때문에 다운? 차라리 없애버리자. 2010.08.12 5838
141 컴퓨터잡담 [악성코드퇴치] 악성코드 처리 방법 1 2010.08.12 9902
140 컴퓨터잡담 [악성코드퇴치] hosts 파일로 경로납치 현상 방지 1 2010.08.12 14026
139 컴퓨터잡담 [악성코드퇴치] NSLOOKUP 경로 확인으로 가로채기 하기 1 2010.08.12 14605
138 컴퓨터잡담 악성코드 mus.exe 제거하기 2010.08.11 16034
Board Pagination Prev 1 ... 37 38 39 40 41 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소