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
  • 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...

  • I Write Like Cory Doctorow

    ... apparently. Well, this is good news. I'm a big fan of Cory. I write likeCory DoctorowI Write Like by Mémoires, Mac journal software. Analyze...

  • test post after restore

    Trying to restore the backup database again. Looks like it might have been a mysql issue. A little unforseen maintenance and one broken RAID controller...

  • What's wrong with the world? Apparently, #scottbaioruinseverything

    Whoa, the boy's going a little loco in la cabeza. Even spawned a new Internet meme. Scott Baio has had some issues of late. He's...

  • sdfsd WTF?

    My keyboard went offline when I plugged in my BB today. I started mashing keys to test it out, and Google made some interesting search...


1 Comment

Excellent - works like a charm.

Leave a comment

Recent Entries

  • The Placebo Effect

    So, how's that homeopathy working for you? The Strange Powers of the Placebo Effect - YouTube...

  • Coffee and a Devil's Star

    Reading another Jo Nesbo book (is that 'Joe' or 'Yo'?) and grabbing a cup at Williams on Northfield. I'm all out of order on this...

  • 5 Reasons No One Is Guestposting At Your (My) Blog

    Image via WikipediaWell, obviously, I've not been looking for guest posters. But apparently, it's a thing you can do to get more content and more...

  • Gearing Up for the 2011 Zombie Invasion

    Image by aeviin via FlickrPut on your brains, the zombies are coming. Zombies make their appearances here and there all through the year, but you...

  • My Mai Tai

    A Trader Vic mai tai, straight from the book. Remember, the only fruit juice in a mai tai should be lime. Yes, well, there should...

Close