I shouldn’t have had such a difficult time finding out how to implement the simplest action possible (IMO) with the API, pulling out a single post from a Blogger blog. The answer I finally came up with uses the newer ATOM API, which is why I couldn’t simply use the class library Beau Lebens and I published a few years ago. If Blogger wasn’t the poor stepchild at Google, we wouldn’t have to be scrounging so hard for simple code like this either–and maybe it’s my poor programming skills that didn’t allow me to see this as quickly as others might–but there you go.
Down to details. Get the BlogMarks PHP client libary (thanks Francois) and load to your server. The code is then trivial:
require_once("/path/to/file/Services/Blogger.php");
function getOnePst($version)
/* returns the text as a string ready to print
$version is either:
"CONTENT" - content of post only
"ALL" - title and content
*/
{
// set up your authentication info
$blogid = "Your blog ID number";
$username = "User Name";
$password = "Password";
// d'oh, probably pass this in as a parameter in a real version
$postID = "Entry to retrieve";
// create the Blogger object
$blogger = &new Services_Blogger($blogid, $username, $password);
// get the post
$ent = $blogger->getEntry($postID);
if (PEAR::isError($ent)) { // error handling
// return the error code, message
$r = $ent->getCode().':'.$ent->getMessage();
} else {
// you could make the return an object or something for
// more sophisticated handling
if($version == "CONTENT") { // content only
$r = html_entity_decode($ent['content']);
} else { // full entry
$ttl = html_entity_decode($ent['title']);
$bdy = html_entity_decode($ent['content']);
$r = "<h2>$ttl</h2><div class="your_post_style_class">$bdy</div>";
}
}
return $r;
}
Use at your own risk, no warranty or guarantee implied or provided, no support offered though polite email requests may be answered. I’m mainly posting this so the next person has an easier time finding the answer, like I said the code itself is fairly trivial and the BlogMarks package does all the real work.