Atom Posting To Movable Type

For the Q Awards 2007, we wanted to have minute by minute blogging.

q awards minute by minute

We used Movable Type for the website, but didn’t want to have to rely on having a laptop available to blog from, so blogging from a mobile phone was the approach we took.

Originally we looked at Twitter for this, but we worried about connection speed. We also looked at Nokia Lifeblog, while good, it doesn’t really allow for just headline posting. Finally, we took the custom code approach.

Movable Type has an Atom interface, it’s what Nokia Lifeblog uses. This lets us post articles, so all we needed was a suitable client. Thankfully, using Perl, there is XML::Atom::Client.

Ben Hammersley provides an great tutorial on using the Atom API in Movable Type.

My code needed to take a line of text and post automatically to Movable Type in a certain category (called “livefeed”). I built a really simple HTML page that could be used by any internet enabled phone. It had one text box and one submit button. Copy entered here and submitted would appear in the Movable Type blog automatically.

I needed some glue Perl code behind this page to make this happen. It turned out to be really simple, and here’s the core functionality. I won’t bore you with CGI handling or display code, just the Atom meat.

my $api = XML::Atom::Client->new;
my $dc = XML::Atom::Namespace->new(dc => '');
my $entry = XML::Atom::Entry->new;
$entry->set($dc, 'subject', 'livefeed');
my $edituri = $api->createEntry($posturl, $entry);
if ($edituri) {
## posted ok
} else {
## not posted, $api->errstr has the error message;

This code assumes you have a few variables in place, those are

  • $username – the poster’s username
  • $password – the poster’s web services password
  • $posturl – the web service’s post url
  • $subject – the copy to post to the blog

Movable Type has two different passwords per user, it is important we use the webservices password and not the users normal Movable Type password.

Now we were posting and creating entries each post, we wanted to show them all on one page. my collegue Ross wrote this block of code to display the posts.

<MTEntries category="livefeed">
<MTIfNonEmpty tag="EntryTitle">
<p class="time"><$MTEntryDate format="%I:%M %p"$></p>

This turned out to be a nice, fast solution to getting content up quickly on the day.

Movable Type Comment Problems

Earlier on the guys at Kerrang posted a rather hot topic on the lovely Mr Manson and his thoughts on My Chemical Romance.

This caused a fever of activity on the website, and unfortunately caused it to corrupt with the following messages appearing in the Movable Type activity logs.

Comment save failed with Insertion test failed on SQL error Duplicate entry ‘6692’ for key 1

Now it took a while digging in the code to work out what was wrong as I’ve not seen this before.

Eventually logging into the MySQL database, showed up the problem.

mysql> check table mt_comment;
| Table | Op | Msg_type | Msg_text |
| kerrang2.mt_comment | check | warning | 12 clients are using or haven’t closed the table properly |
| kerrang2.mt_comment | check | warning | Size of datafile is: 2999316 Should be: 2998080 |
| kerrang2.mt_comment | check | error | Found 6561 keys of 6559 |
| kerrang2.mt_comment | check | error | Corrupt |

Ahha! The comments table is screwed. The solution is to run the following…

mysql> repair table mt_comment;
| Table | Op | Msg_type | Msg_text |
| kerrang2.mt_comment | repair | warning | Number of rows changed from 6559 to 6561 |
| kerrang2.mt_comment | repair | status | OK |

Comments on Movable Type now work fine.

Posting To Movable Type 3.3 Using Nokia Lifeblog

We’ve been installing Movable Type as a blogging solution at work for various sites recently.

We’d been using Typepad, the hosted version of Movable Type for a while, but wanted some extra flexibility and functionality.

One problem we came across was the lack of support for Nokia Lifeblog on Movable Type, compared to Typepad.

Thankfully Martin Higham has worked on this in the past, and even used my old notes on the Nokia Lifeblog Posting Protocol.

However, the current version of Movable Type is 3.3, and Martin’s work only extends to 3.2.

I took Martin’s code, which modifies and modified it so it works on Movable Type 3.3. You can download my Nokia Lifeblog compatible for Movable Type 3.3 here.

Make sure you follow Martin’s instructions for Movable Type 3.2 as the method is exactly the same and the same caveats apply (namely, this could well break other Atom tools that use your blog as it has to disable some WSSE authentication).

I hope you find it useful!

UPDATE: 22nd November 2006

With version 2.0 of Lifeblog and web upload functionality from Nokia phones, the authentication method has changed slightly. A new version of that works with Lifeblog 2.0 is now available.

UPDATE: 26th June 2007

Neils Berkers has been in touch to say he’s adapted the script so it now works with Movable Type 3.35, Lifeblogging Fixed.