Getting Married and Posting to Blogger

As of June 20th, I am now married. It was also my birthday and Father's Day (we just found out she's pregnant!), so I am not only a very lucky man, but I'm going to be totally screwed on presents.


And to make things relevant, I recently asked how to post to from Perl. I was also asked to share the solution. Here it is.

Egor Shipovalov on the mailing list posted some working code he used to post to from emacs, but it didn't work for me. Seems one of the required modules, Net::Google::GData was accidentally removed from the CPAN (it was been readded after I contacted the author) and after I grabbed it from the backpan, the primary module, WWW::Blogger, failed horribly with the message "Your config file /Users/ovid/.www_blogger_rc is readable by others!". I thought that was odd because I didn't have such a file, but the module created it for me. I had to edit that to add my username and password to get WWW::Blogger to work. This is not documented and, apparently, that's deliberate.

It's also the only way to supply your credentials to the module. The following line does not allow you to authenticate, even though one might think so from the docs:

WWW::Blogger::XML::API::set_account( $username, $password );

In any event, I finally managed to get it working and while what follows is hardly generic, it does post to blogger.

#!/usr/bin/env perl

use Modern::Perl;

use LWP::Simple;
use XML::XPath;
use WWW::Blogger::XML;

use Readonly;
Readonly my $BLOG_ID => ...;

my $post_body = <<'END';
<entry xmlns=''>
  <title type='text'>Post!</title>
  <content type='xhtml'>
    <!-- content start -->
    <p>This is a post</p>
    <p>Are we good to go now?</p>
    <!-- content end -->
  <category scheme="" term="testing" />
  <category scheme="" term="again" />

# This works because I have a ~/.www_blogger_rc file
# Create the request.
my $request = HTTP::Request->new(
    $WWW::Blogger::XML::API::url . "/feeds/$BLOG_ID/posts/default/",
    [ Content_Type => 'application/atom+xml' ], $post_body,

my $result = WWW::Blogger::XML::API::ua_request($request);
die $result->status_line unless $result->is_success;
my $xpath = XML::XPath->new( xml => $result->content );
my @hrefs =
if ( @hrefs > 1 ) {
    warn $result->content;
    require Data::Dumper;
    warn Data::Dumper::Dumper( \@hrefs );
    die "PANIC: More than one response href found";
say $hrefs[0];

Good luck with that!


Congrats... on, well, everything :)

"so I am not only a very lucky man, but I'm going to be totally screwed on presents"

Hehe, I know the feeling :) (wedding date is 2 days away from the my birthday)

Congratulations on everything, including getting the post-to-blogger code working :)

Most of it seems straight-forward, but what is the "die "PANIC: More than one response href found";" part for?

I got married on Leap Day...thinking an anniversary every 4 years. We had two weddings. So now every 4 years...we celebrate to anniversaries.

Congrats by the way!

Happy belated wedding!

About Ovid

user-pic Freelance Perl/Testing/Agile consultant and trainer. See for our services. If you have a problem with Perl, we will solve it for you. And don't forget to buy my book!