前回の記事に引き続きAtomAPI用。
PHPとcURL使用。
PHPとcURL使用。
<?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); ?>
コメント