views:

166

answers:

2

I'm trying to automatically post to blogger using Perl's Net::Blogger but it keeps returning false and not posting. The main portion of my code looks like this:

use Net::Blogger;

my $blogger = Net::Blogger->new({
    debug    => 1,
    appkey   => '0123456789ABCDEF', # doesn't matter?
    blogid   => $blogid,
    username => $username,
    password => $password,
});

my $result = $blogger->newPost({
    postbody => \'<p>This is text</p><hr/><p><strong>Whee!</strong></p>',
    publish  => 1,
});

use Data::Dumper;
print Dumper($result);

Sure enough, $result is 0 and in checking the blog, nothing has been posted. The error I'm getting when I enable debugging is:

Element '' can't be allowed in valid XML message. 
Died. at /Library/Perl/5.10.1/SOAP/Lite.pm line 1410.

What am I doing wrong?

If you can suggest an alternative to Net::Blogger, that would be fine.

Update: if I don't enable debugging, it hangs for quite a while when trying to post.

+1  A: 

Alternative as you requested: after all the different blogging APIs, a standard in the form of RFC 5023 emerged.

Atompub works fine.

daxim
And that looks fantastic, but I can't find the atompub service URL for blogger. Are there any working examples you can point me to?
Ovid
Found http://code.google.com/apis/blogger/docs/2.0/developers_guide_protocol.html#CreatingPublicEntries on the BloggerDev discussion group.
daxim
daxim: yeah, I was already working off of that. The problem is that atompub starts with a service, but the URL is not clear to me. Every time I've tried to munge it to make it work, I've failed. I can sit down and try to read the entire spec and make this work, but I'm frustrated that Perl used to own the Web and I can't find a single working example of this anywhere. Only disconnected bits and pieces. What should be a five minute coding job is turning into hours of reading cryptic documentation.
Ovid
Ovid: it's to give you the feeling for what it's like to work in most other languages most of the time :)
ysth
+1  A: 

I can understand your frustration, I don't like it when I try to use a CPAN module which is seductively named (i.e. looks like a good scratch for the itch) but is ultimately not useful. However, Net::Blogger had its last update in 2006 so I think it would be incredible if it still worked as originally intended, given that blogger has been evolving over the years.

Per daxim's rec, I made a quick attempt to install Atompub on OS X via CPAN.pm, but failed due to a hard dependency on Perl::Critic, which won't install. I figure I know how to fix this but I'll need a better reason than this to go to the effort.

I saw this note in the Net::Blogger perldoc which if nothing else provides a hint on another module to try, for anyone who didn't feel like beating Atompub into submission:

The Atom API

In January 2004, Blogger announced their support for the Atom API.

As of this writing (version 0.87) this package does not support the Atom API. If you need to do things Atom-ish, your best bet is to use the XML::Atom package.

virtualsue
It's a shame XML::Atom is not documented, but it installs first try. I'll try to apply it to this problem today.
virtualsue