ܻؤ1顪30奵꡼ޥܥ

ITȤƯ30奵꡼ޥΥ饤ߥ󥰵Ͽ

AtomAPI

ʥ֥AtomAPIݤʤε
ϸƤäѤƱ褦˺äƤͤߤ

Ȥ櫓ǡפ֤Ĵľ
ΥȰ㤦ʬԥååס
äѤWSSEǧݥȤǤ줵̤ФȤϤʤꡣ


$nonce = sha1(md5(time()));


ʸ鲿Ǥ⤤Ȥϻפɡ


$pass_digest = base64_encode(pack('H*', sha1($nonce.$created.strtolower(md5($password)))));


դä
ʸˤ󤸤ʤʸˤ롣


Ȥgetǵη̤postURLȤäƵꤲߤ

Ѥ
³ɤ
    Υȥ꡼ϤƤʥ֥åޡɲ

livedoorBlogAtomAPI˰³֥ä㤦Ȼפäϥޤä
ƱAtomAPIƱǹԤȻפä㤦餷

Ĵ٤ƤߤWSSEǧڤȼݤ
Ǥ⤤Ĵ٤ƤƱ褦˺äƤͤϤƤ⡢褷ƤͤĤʤ

ɵݤޤ(2010-02-03)  >>εء



ޤĴ٤livedoorBlogȰ㤦Ȼפʬpass_digestκʬ

livedoorBlog
$pass_digest = base64_encode(pack('H*', sha1($nonce.$created.$password)));

֥
$pass_digest = base64_encode(pack('H*', sha1($nonce.$created.strtoupper(md5($password)))));

ѥɤmd5Ȥʸ餷Ȥξ
ǥޤۥȤ狼ޤ󡣡

֤äƤ쥹ݥ󥹤
CurlResponse Object
(
    [body] => 
X-WSSE authentication required
    [headers] => Array
        (
            [Http-Version] => 1.1
            [Status-Code] => 401
            [Status] => 401 Unauthorized
            [Set-Cookie] => BIGipServerPool_comment=3395622060.20480.0000; expires=Sat, 17-Oct-2009 01:32:13 GMT; path=/
            [Date] => Fri, 16 Oct 2009 02:18:33 GMT
            [Server] => Apache
            [Content-Length] => 83
            [Content-Type] => application/x.atom+xml
        )

)

ʤ󤫰㤦ȤǴְäƤΤ
Ѥɤϰʲ

³ɤ
    Υȥ꡼ϤƤʥ֥åޡɲ

ε˰³AtomAPIѡ
PHPcURLѡ

<?php
require_once 'cURL.php';

$atomapi_url = "http://cms.blog.livedoor.com/atom/";
$livedoor_id = "your livedoor id"; /* livedoorID */
$password = "your password"; /* ѥ */
$category = "1"; /* ƥ */
$title = "sample"; /* ȥ */
$text = "content"; /* ʸ */

$created = date('Y-m-d\TH:i:s\Z');
$nonce = pack('H*', sha1(md5(time())));
$pass_digest = base64_encode(pack('H*', sha1($nonce.$created.$password)));
$wsse =
  'UsernameToken Username="'.$livedoor_id.'", '.
  'PasswordDigest="'.$pass_digest.'", '.
  'Nonce="'.base64_encode($nonce).'", '.
  'Created="'.$created.'"';

$text64= base64_encode($text);

$rawdata =
  '<?xml version="1.0"?>'.
  '<entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">'.
  '<title type="text/html" mode="escaped">'.$title.'</title>'.
  '<dc:subject type="text/html" mode="escaped">'.$category.'</dc:subject>'.
  '<content type="application/xhtml+xml" mode="base64">'.$text64.'</content>'.
  '</entry>';

$headers = array(
              "X-WSSE" => $wsse,
              "Content-Type" => "application/x.atom+xml",
              "Cache-Control" => "no-cache",
              );

$curl = new Curl();
$curl->headers = $headers;
$curl->options = array("POSTFIELDS" => $rawdata);
$res = $curl->post($atomapi_url);
?>
    Υȥ꡼ϤƤʥ֥åޡɲ

ΥڡΥȥåץ