Integrating Your Movable Type Site with Plurk

If you’ve been reading the blog for the last little while, you know that I’ve been hanging out on Plurk recently. Naturally, that means that I have been playing with Plurk as well, and trying to integrate it into my daily routine. When I used Twitter, it meant that I used Twitterfeed to create Tweets from the entries that I posted here. The problem is that Plurk has no such interface, as it doesn’t have an API, so no such solution exists.

Luckily, Plurk power-user Ryan Lim came to the rescue. Not long ago, he released RLPlurkAPI, a PHP-based API into Plurk. It’s not an official API, but it’s good enough to allow outside services to access Plurk from the outside. It isn’t Twitterfeed either, but what it did was allow people such as myself to see that it’s possible to access the system from the outside. Unfortunately, I still couldn’t do it, and I needed some more help.

Getting the Perl API to Work

Enter Andy Armstrong, Perl Monger extraordinaire. Within a very short period of time, he had announced the release of WWW::Plurk, a Perl-based module for accessing Plurk from the outside. Now we’re talking – this means that Movable Type users are getting closer to getting in on the action – and more importantly, it means that my own efforts to make the connection, which had hit a wall, now had some help on making things work!

I continued to look at both Andy and Ryan’s work, and before long I had made my own inroads on accessing Plurk from the outside. I was able to pull out friend data – using a slightly different method than either of the others were using – and I also was able to send a plurk into the system (using roughly the same methods that they used). However, I decided that I would stop there, because frankly I didn’t need the ability to approve friend requests or pull out plurks. There is a widget for the plurks, and I just wanted to be able to get at certain pieces of the system.

Here Comes MT-Plurk

After a bit of tweaking, such as eliminating duplicates from updating more than once by writing a record into the PluginData table, and adding some logic to help create better plurks due to the 140-character limit, MT-Plurk was born, and it seems to be working well. After downloading, just unzip it to the Plurk directory under the MT plugins directory, and you’re ready to begin.

You will need to visit the settings screen, where you specify your Plurk username. If you don’t care about sending plurks into the system, you’re actually done at this point. The only thing needed to retrieve friend information is the username (this is the area that differs from Andy and Ryan’s work). In fact, because of this, I might change the plugin in the future where you can retrieve anyone’s friend information, but at the moment it’s only for a single user. Anyway, if you’d like to send plurks based on new entries, you’ll also need to include your Plurk password, the language code to use (defaults to en) and the qualifier to use (defaults to shares). Be careful with the language code and qualifier – if you use invalid values, then the plurk will not post correctly!

The final piece of the puzzle is a simple checkbox that tells the system to post when new entries are saved. If unchecked, entries will not post. If checked, entries will post. It’s as simple as that. Also, if you don’t include your username or password, entries will not post.

How MT-Plurk Does It’s Work

When an entry is saved, a small routine checks the entry before posting to make sure it will fit into the 140-character space. If the permalink is longer than 134 characters, then the link itself is used as the entire plurk (I may implement support for URL-shortening services in the future, but they aren’t there right now). If the permalink is between 121 and 134 characters, then the permalink is used, and the text (link) is added. It won’t look pretty, but it won’t break, either. If the permalink is shorter than 121 characters, then the title is appended and the entire string is checked to see if it is 140 characters or longer. If it is too long, then it is trimmed to fit. This might mean you lose a few characters, but at least your plurk looks okay!

There is also another option with MT-Plurk, and that is pulling data from Plurk – namely, if you want to display friend information. You can create a simple construct to show you friends, and some basic information about them.

Using the <MTPlurkFriends> container tag, you are able to loop over all the friends in your account (this uses the username specified in the settings, which is why that is required). Within the container tag, you have several template tags to display content:

<$MTPlurkFriendsDisplayName$> – display name
<$MTPlurkFriendsDisplayName$> – full name
<$MTPlurkFriendsNickName$> – username
<$MTPlurkFriendsGender$> – gender
<$MTPlurkFriendsKarma$> – karma (to two decimal places)
<$MTPlurkFriendsLocationName$> – location
<$MTPlurkFriendsUserID$> – user ID

You can do something like this to display a list of your friends and their karma ratings:

<MTPlurkFriends>
 <$MTPlurkFriendsNickName$> <$MTPlurkFriendsKarma$>
</MTPlurkFriends>

Obviously you can make this a lot more complex too – that’s all up to you! Get MT-Plurk now and you’re ready to go after a quick configuration process. Everything you need should be included with the package. The only modules not included are HTTP::Cookies and LWP::UserAgent, but those are fairly common with most Perl installations. MT-Plurk is compatible with MT 3.36, and should work fine with MT4 as well. The Net::Plurk module that it comes with is written in such a way that you should be able to use it with other applications if you are so inclined.

More About Accessing Plurk

These aren’t the only ways to access Plurk. Luis Gustavo announced his C# Plurk API and there is a web-based Plurk API in fairly constant development, so things are definitely moving. If you don’t see what you want, keep your eyes open. If you haven’t checked out Plurk yet, you should do so!


Posted

in

Comments

4 responses to “Integrating Your Movable Type Site with Plurk”

  1. Chad Everett Avatar

    Hi Jeff –

    Thanks for the note, and you can actually just re-download from the same link to pick up the current version (0.0.3). I’ve been working for a while, and think I have finally solved the re-update problem.

    The issue was that even though it was never supposed to re-post updates, it would never correctly get the Plurk ID, so it never knew that it had actually posted a Plurk correctly. I’m pretty certain that it has done so at this point (at least, in my limited testing it seems to work okay).

    Download it and give it a go – just wipe out the old plugin directory and replace it with the current version. All your settings will be retained, as they are stored in the database.

  2. Jeff Summers Avatar

    Great article and good job on MT-Plurk. I’m using version 0.0.2 but I’ve noticed some odd behavior. It will post to Plurk if I schedule in the future or if I’ve made changes to an existing entry that has already been published. Are there configuration settings that can be configured so that it will only post when an entry is first published?

  3. Chad Everett Avatar

    Excellent, Yves, thank you for making it and bringing it to my attention!

  4. Yves Avatar

    Hi Chad,

    maybe you and your readers are interested in my Plurk plugin for the Action Streams plugin.