I've been using the MT-Twitter plugin for a while now, so that when updating the MissingLinks page, a corresponding twitter posting is made. It used to be using bit.ly to shorten the URLs (prior to the big server crash, I was using icanhaz.com, but lost all my code when the RAID controller on the server failed). Sometime in mid-November, the bit.ly URLs just disappeared, making me thing something went wrong on twitter's API. Either that, or something went wrong on my server, which I hadn't even touched that month.

So, I looked around for some suitable Perl code to re-introduce the bit.ly API calls that mysteriously went missing. The answer was a chunk of code from openclue.org (now apparently defunct). I'm reposting it here, so it might help someone out (myself included -- I'm backing stuff up properly now).

The twitter.pl script just needs a few extra lines. I inserted this code just after the "my $intro" line in the _update_twitter function:

my $bitly = LWP::UserAgent->new;
my $url_response =
    $bitly->get("http://bit.ly/api?url=" . $obj->permalink);
my $small_url;
if($url_response->is_success) {
   $small_url = $url_response->content;
} else {
   $small_url = $obj->permalink;

Then you have to update the part of the script which creates the twitter message. Replace the original $text string with the $small_url string:

# my $text = $intro . $entry->title . ' ' . $obj->permalink;
my $text = $intro . $entry->title . ' ' . $small_url;

Presumably, you can use any URL shortener API you want -- just insert the proper API call. Or, if you're enterprising, make your own URL shortener. That way, you own all the links.

Someone even came up with an idea to use .htaccess 301 redirects to bounce a link ending with <mt:EntryID> to the proper <$mt:EntryLink$>. Of course, this really only works if your domain name is short to begin with.

Related Entries
  • How To Get Traffic To Your Blog

    I could have just tweeted this post from Writer's Life.org, but that wouldn't have brought anyone to my blog. Ah, I kid. But, there's some...

  • When Your Writing Is Crap

    I feel for this guy. I've been there. This is the third time it has happened to me, and it prompted me to think about...

  • Dirty Coffee Cup and Tagging Test

    This image is just a filler for this moblogging post, which is testing out tagging for Movable Type. I'm just trying to see if I...

  • FPSRussia Guy was Shot to Death

    Oh, man. This is sad. I actually secretly liked this guy's videos. He had this great fake Russian accent and fired a lot of guns....

  • Bloglines back from the dead

    Very good news. They were the best, fastest, and most solid aggregator around. We're happy to announce that Ask.com has entered into an agreement with...

1 Comment

Excellent - works like a charm.

Mailing List Signup

What? There's a mailing list? Sign up for the Mailing List

About Me

I suppose if you've been reading my site for any length of time, you're probably curious to know who I am, and why I think people will read my blog. Online, I'm known as Zuckervati, mostly because it's easy...
» More ...

Follow Me on Twitter

Recent Entries

Tag Cloud

politik / film / video / skeptic / cewl / techno / humour / haxors / nosh / can-con / gaming / religion / weird / sex / funny / eco / music / stupid / photos / cocktails / George Bush / blogosphere / flickr / travel / evolution / politics / creationism / creationist / mobile / awful / photography / Star Wars / awesome / geek / bartending / coffee / drinking / mixology / alcohol / liquor / bartender / cocktail recipe / cats / food / Savoy Cocktail Book / science / Lovecraft / parody / books / Cthulhu / articles / TV / pets / John McCain / promos / Movable Type / cartoons / sci-fi / Canada / Radio Zuckervati / cool / Roger Ebert / system / atheism / comics / reviews / technology / zombies / anime / anonymous / MMO / Star Trek / television / writing / Alinea / animation / Batman / Futurama / Halloween / horror

Twitter Stream

D H McKee's bookshelf: to-read

Sunset and Sawdust
tagged: to-read
The Thicket
tagged: to-read
tagged: to-read