MT-Twitter: A Movable Type Plugin

Hacks, Movable Type64 Comments

Update: 2012-10-23 – I have decided to no longer develop this plugin. Sorry.

Why? Twitter changed their APIs recently. The new APIs no longer allow a non-authenticated user to get the list of tweets. This is how this plugin worked. Instead, you have to be authenticated via OAuth. In order to do that, I would have to embed my own Twitter dev keys into the plugin, which is a text file, for the world to see. Not a good idea. The other option is to have you, the user, get your own dev keys. I am not prepared to deal with the support required.

So I am leaving this plugin behind for now…


Current version is 4.1.0.1 released on 2010-05-11

Contents

What This Plugin Does

Heard of Twitter? Twitter is a social networking and micro-blogging service that allows users to send updates via SMS, instant messaging, the Twitter website or 3rd party applications. But you probably already knew that or you wouldn’t be reading this.

While I think Twitter is fun, I don’t like spreading my posts all over the place. You might be posting on your blog, on Twitter, on Facebook, on MySpace, etc. I want all my content to ultimately be on my blog but I don’t mind it being in other places too.

So I decided to do a 1-way sync with Twitter to Movable Type. That way I can use Twitter when I want to, but my Movable Type blog will be updated with all the content in the background.

Using the background tasks functionality in Movable Type, this plugin will query your Twitter account for your latest updates, or “tweets”. When it sees a new one, it will create an entry in your blog for that tweet. Various properties of the blog entry are used. The title isn’t really interesting because tweets don’t have titles. The body of the entry is the text of the tweet. A direct URL to the tweet on Twitter.com is put into the extended entry field. In the end, you have tweets appearing on your blog so your non-Twitter friends can see what you are up to just by reading your blog.

I could have used a separate database for the tweets, but I decided it was cooler and more integrated to use normal blog entries. Then you can use a variety of Movable Type template tweaks to show/hide the tweets or customize their display.

Requirements

  • Movable Type version 4 and higher.
  • Perl version 5.8.8 or higher.

Installation Instructions

  1. Download the latest version of the plugin.
  2. Unzip the contents of the file.
  3. Copy the file Twitter.pl to your Movable Type “plugins” directory.

    (If you don’t have a plugins directory, create a plugins directory in the same directory where your mt.cgi file is located. Then upload Twitter.pl into the newly created plugins directory.)

  4. Go into your blog settings. Click on the Plugins tab. You should see an entry for MT-Twitter. Click on Show Settings and configure as desired.
  5. If you have any trouble, be sure to check the Movable Type Activity Log for errors.

Configuration

There are a variety of options that you can set when configuring the plugin:

Configuration

Frequently Asked Questions

  • Q: I set everything up but its not publishing. What am I missing?
    A: Be sure that you have Movable Type’s background tasks setup with the script run-periodic-tasks. This is shipped with Movable Type in the tools directory.

Examples

1. To customize the display of tweets in your templates, you can use a category filter. The label parameter should be set to the name of the category you posted your tweets under. Tweets is the default category name.


<MTEntries lastn="15">

<MTIfCategory label="Tweets">

<p>I am a tweet!</p>

<MTElse>

<p>I am NOT a tweet!</p>

</MTElse>

</MTIfCategory>

</MTEntries>

Purchase

The cost for this plugin is $10 USD.

License

This software is protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties. This software is licensed, not sold.

NO WARRANTY. THE PRODUCT IS DISTRIBUTED “AS IS” AND WITHOUT ANY WARRANTY AS TO MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR ANY OTHER WARRANTIES EITHER EXPRESSED OR IMPLIED. THE AUTHOR WILL NOT BE LIABLE FOR DATA LOSS, DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS SOFTWARE.

Download

Download the current version after purchase from the link below. Past versions are not archived.

Version History

4.1.0.1 — 2010-05-11
  • Fixed issue with links to Twitter users where colon was appearing after name.
4.1.0.0 — 2010-03-13
  • Added ability to customize the title of the tweet.
  • Added the ability to convert user references and hashtags to links.
  • Changed the converted links to show the link title instead of the word Link.
  • Added the ability to publish tweets as drafts. Nice for troubleshooting and previewing.
  • Added ability to run the plugin’s task code from the configuration screen.
  • Additional debug logs for troubleshooting.
4.0.0.1 — 2009-11-24
  • Updated plugin settings to use fancier MT user interface.
  • Fixed issue where Convert URLs option assumed incorrect URL end.
  • I cleared out the comments on this plugin because many no longer applied.
4.0.0.0 — 2007-08-17
  • Updated some registration techniques in the plugin to make it work with MT4.
  • Added abliity to exclude tweets based on regular expression.
  • Changed major version to 4 to indicate MT4 requirement.
1.0.1.0 — 2007-08-13
  • Added a configuration option for the publishing of replies (@username).
1.0.0.0 — 2007-04-09
  • Works for me.

Contact

For questions, suggestions, bug reports, and anything else related to this plugin, please e-mail brandon@fuller.name or leave a comment.

  • Great timing Brandon. I was just getting ready to add this to a newly upgraded site. Appreciate the update. Any thoughts on a tweetmeme plugin? Or can you point to a good solution similar to the WordPress plugin? I’ve found a couple hacks that just don’t integrate cleanly. Thanks again!

  • No thoughts on it. I usually only build the stuff I use myself — and I don’t have the need – yet!

  • Completely understand. I’ll keep my eyes open. Peace.

  • It works great.

    A question:

    After installation, it only grabbed the 10 most recent tweets. Is there a way to get to grab *all* of them?

  • I figured it out. Not optimal, but I just changed the pull number in the plugin. Thanks for a great plugin!

  • That’s the only way right now. I never exposed it as a setting because I was afraid novices would set it high and leave it there.

  • Novices? Hey, that’s me!

  • hillary

    this is great! although, too bad i’m not smart enough to understand how to set up the RPT script or set up a cronjob. over my head…

  • Google is your friend. There are an infinite number of web pages that describe how to do such a thing.

  • hillary

    yes, thanks… still over my head. 😀

  • Will this work on MT5?

  • I don’t know yet. I have not upgraded. And last I checked, SixApart didn’t have the plugin upgrade instructions available.

  • I’m on MT5, and it works just fine.

  • Thanks.

  • Any chance to get that regex updated so it doesn’t substitute “Link” in place of the link’s url? Additionally, is there a chance you could work in links to any mentioned hashtags or other users (ala @blah). This page has the functional regex for all three of these things, but I thought you might want to incorporate it into the plugin itself.

  • Thanks for the suggestions. Good stuff to add in.

  • I don’t want to sound impatient, but do you have guestimate as to when you might incorporate those changes? Do you think you going to create new user-selectable options for each one, or just make it an all-in-one option?

  • I usually spend some of my weekend free time on my various hacks. This plugin gets updated monthly or so. I usually collect a list of things people are looking for and do them all at once. So I don’t have an ETA.

  • That’s fair. I appreciate the response, and look forward to the enhancements.

  • While I’m requesting new features, it would be nice to have the option to have the title be dynamic – specifically to have the title be the body of the tweet. Again, peeking into the code of the plugin, I see where it seems to be possible, but this might be something others might want. Maybe some people might want to prepend their tweet/entry with something customizable (like the freeform text currently available). Personally, I’d prefer to use the the first option I mentioned, especially for multi-blog publishing it’s far more useful to have a meaningful title, as opposed to using conditional publishing to potentially pull over the body instead of the (useless) title.

  • All of your wishes have been granted. Version 4.1 is available now.

  • That’s awesome! Thank you very much! Hopefully others find the new features as useful as I do. Well worth the money.

  • Plug-in seems promising, but a bit buggy for me. It’s pulling in the tweets, but assigning author “(user deleted)”! Any clue what the problem might be? I had installed an older version of the script ages ago, and had edited a few lines to tweak for my purposes, but the behavior above is with a fresh copy of the latest perl. Can’t help but think that’s related but cannot imagine why.

  • It uses the author/user ID that configures the plugin. Meaning its stored when you are editing your settings for this plugin. Be sure to go through that once to get your user ID in place.

  • I have run-periodic-tasks being called every 8 minutes or so but it’s not running the twitter script. How do I ‘attach’ the plugin to the run-periodic-tasks script?

    It works great when I run Update Now from the plugin config and the updates are posted to the blog on the next pass of the run-periodic-tasks but I’m obviously missing a step somewhere…

  • The script itself registers the job. So if the plugin is installed (which it sounds like it is since you see the buttons) then you are good there. It only polls every hour I believe.

  • It’s been a few hours now since I posted on twitter and run-periodic-tasks keeps reporting ‘TheSchwartz::work_once found no jobs’

    I’m running MT4.32 on Windows XP if that makes any difference. I would assume that there are other people who have periodic-tasks working on XP.

    I have ‘Debug Log’ set in the MT-Twitter settings but there are no entries in the Activity Log.

    I’m still unclear how the run-periodic-tasks script knows to run the twitter plugin script. Does it go through the plugin folder and run everything?

  • The plugins themselves have code in them that registers tasks that they want to run. This plugin says “run me every 15 minutes”. So periodic tasks will fire it off when it sees that amount of time has passed. You will see a “Looking for updates” log message. Its the same one that gets posted when you run the plugin manually via Update Now. If you don’t see it, I suspect your periodic tasks is not running or is throwing an error. I often see people incorrectly launching it with path problems. You should change directory into the tools directory and run it from there.

  • Thanks for your quick replies.

    I discovered the ‘system’ activity log and in there were errors saying it couldn’t write a lock file in my /tmp directory. Because I didn’t have a /tmp directory. I created the directory and the background tasks (including TM-Twitter) are working tickety-boo now.

    Super!

  • Now that it’s working I’m discovering a couple of things. The run-periodic-tasks script is spitting this out when running the MT-Twitter plugin:

    ‘jsonToObj’ will be obsoleted. Please use ‘decode’ instead. at C:\webroot\XXX\mt3\plugins\Twitter.pl line 214

    Also, when retweeting from within Tweeteck it adds a colon after the @username and MT-Twitter is including that colon in the URL it creates for the user. So RT @GuyKawasaki: is becoming twitter.com/GuyKawasaki: rather than twitter.com/GuyKawasaki and the link fails.

  • Also, is it possible to make the link to the original tweet in the extended section an active link rather than plain text?

  • Fixed the issue with the colon in 4.1.0.1 available now.

  • You can edit the plugin source to do that if you wish.

  • Updated it thus:

    $entry->text_more( ‘{id} . ‘>http://twitter.com/‘ . $twitter_username . ‘/statuses/’ . $tweet->{id} . ” );

    Seems to work 🙂

    Thanks!

  • Yep, that’s got it.

    Thanks. 🙂

  • I can’t seem to get that change to work. I get the error ‘Plugin error: /home/jsign/webapps/culturesnob/mt/plugins/Tw itter/Twitter.pl syntax error at /home/jsign/webapps/culturesnob/mt/plugins/Tw itter/Twitter.pl line 255, near “http:” BEGIN not safe after errors–compilation aborted at /home/jsign/webapps/culturesnob/mt/plugins/Tw itter/Twitter.pl line 385. Compilation failed in require at lib/MT.pm line 1280. (IP: 66.249.71.117)’

  • The code didn’t paste into the comment quite right … see if this works better:

    $entry->text_more( ‘<a href=http://twitter.com/’ . $twitter_username . ‘/statuses/’ . $tweet->{id} . ‘>http://twitter.com/‘ . $twitter_username . ‘/statuses/’ . $tweet->{id} . ‘</a>’ );

  • Nope, still didn’t paste right. Here’s an IMAGE of the code:

    http://www.greyfence.com/public/pic/TwitterCode.jpg

    Note that all the code should be on ONE LINE. I had to break it up to fit it in the image.

  • I’m getting that same error from the run-periodic-tasks script

    ‘jsonToObj’ will be obsoleted. Please use ‘decode’ instead. at /var/www/vhosts/depressedfan.com/cgi-bin/plugins/Twitter.pl line 214

    Is this problematic?

  • Pedro

    Brandon, I’m now getting a warning error, potentially due to some changes on Twitter’s part:

    ‘jsonToObj’ will be obsoleted. Please use ‘decode’ instead. at /path/to/my/mt/plugins/Twitter.pl line 214

    Although it’s still running correctly (currently), who knows Twitter’s timetable to fully deprecate and kill off this option.

  • Its the Perl library that the plugin uses. It doesn’t hurt anything. I need to upgrade it someday.

  • Pedro

    Good to know. I’ll tell my auto-rebuild cron job to shut up in the mean time.

  • sarudama

    hi Brandon,

    I was/am a fan of MT-Twitter way back when it was freeware. I’m just curious what the $10 price tag gets me in terms of future updates. Will I need to pay every time Twitter upgrades its authentication security? Or will I be covered with my current purchase?

    As always, Thanks much,

    sarudama

  • I got sick of spending time debugging other peoples stuff for free. This way I get something in return.

    I won’t make you pay again ever.

    I try to keep the plugin up to date with major new developments but no promises. Just best effort.

  • sarudama

    hi Brandon. Its me from 11 minutes ago… I purchased your plugin and now see that there is an “update now” link in the preference settings. I think that answers my earlier question. Good luck to you, my friend!

    sarudama

  • Has anybody else run into an issue with this plugin where in a multi-blog installation, the plugin sometimes publishes tweets to the incorrect blog?

  • Ian_Henry

    Hi, can someone confirm that this plugin uses OAuth with Twitter and will import protected tweets?

  • It reads your public tweets. So it doesn’t need OAuth.

  • I just bought this plugin yesterday and it’s working great! I wondered if you might consider a new feature. It would be awesome if the plugin could detect a TwitPic URL in a tweet, and instead of including the URL in the blog post, embed a thumbnail of the photo, linked to the full size version.

  • Understood but I probably will not add that.

  • Dcannell

    Love this plug in..it works as it should but the title is a bugger… I have it currently set at “tweet”…. and it brings in the whole tweet… For example: This is the title and the tweet… “How social media can be used for learning http://zite.to/fUigf2 via @Ziteapp”

    I would like to figure out a way to take just the beginning and take out everything including the Http: Any of you programmers have an idea how I can make that work.

    I am sending about 10-20 tweets a day from my ipad to twitter and would also like them to post to my blog…but a standard title of Darren’s tweet or something is boring so I changed to tweet which is ok except it includes the whole darn tweet so I have to go into my blog every night and delete the web address and @ziteapp from every title…if there is not solution out there no biggie…

    It would be cool if the tweet would expand the information from the link into a blog posting like it does with the paper.li or something like that…

    Anyways what started as a plain thank you for a plugin that works the way it described it turned into a wish list…

    D. Cannell

  • Dennis

    Hi Brandon, I’ve just installed MT-Twitter but can’t get the run-periodic-task working. I’ve spent a few hours looking up examples and tuts to try to figure it out for myself but I’m not a programmer and can’t get the plugin to push tweets into my blog. I’ve pasted this into the run-periodic-tasks file:

    0,15,30,45 * * * * cd /home/49971/domains/kitpin.com/cgi-bin/movabletype/; perl ./tools/run-periodic-tasks -verbose >> /var/log/httpd/mt.log

    nothing seems to happen.

    After that I’ll need to get mt to publish the index file with the tweet entry. Should that line of code get mt to do that as well?

    Sorry to bother you but I’ve hit a brick wall.

  • Looks about right. Did you actually set it up to run as a cronjob by running “crontab thefilewiththestuffaboveinit”?

  • Dennis

    I think I got it working.. i used media temple’s own cronjob (from their system panel) to trigger run-periodic-tasks

    I did however got some error like that johnd mentioned before:

    ‘jsonToObj’ will be obsoleted. Please use ‘decode’ instead. at /var/www/vhosts/depressedfan.com/cgi-bin/plugi… line 214

    You replied before about how this got resolved, I’ve got the lastest plugin version but I still go the error. So, me not being a programmer and all, I simply changed:

    my $tweets = $json->jsonToObj( $response->content );

    to:

    my $tweets = $json->decode( $response->content );

    it appears to work lol.

  • Thanks for the follow-up. I will try and make that change.

  • Mike

    Looks like this project may not be active, but here’s my .02 for future features:

    Daily digest mode – having each tweet come in as a separate entry is simple but my RSS customers are after my head

    Additional feed items – adding Facebook or whatever

    Thanks!

  • It does what its supposed to do…and what I wanted it for…but I haven’t been developing tons of other features because I haven’t needed them.  So I take things under consideration as they come.

  • Seann

    Curious…  Has anyone used this with 5.12?  Also, have many people reported issues with multi-blog installations?

    I understand and appreciate your comments about this doing what it was designed for, and that MT isn’t as active as it was a few years back so not many people are focusing on developing for it these days.  However, that said, if it works I would like to try it out.

    Thanks.

  • Hi, I have a MT 4.x installation with many blogs and users (more than 300), can this plugin be configured on a per-user basis? or is it one global configuration for the whole MT installation.

    Regards

  • its per blog.

  • D

    This plugin stopped working for me on October 3, 2012 (running MT 4.37). I’ve tried everything I can think of (reinstall, etc.), but new tweets no longer publish to the blog.

    This could be because I have an older version of the plugin running (i.e., I’m running 4.0.0.0). Is there a way to download the latest version without paying for it again? I’m pretty sure I paid for it the first time, but I don’t have anything close at hand to document that. Best to pay again?

  • Twitter changed their APIs and the plugin stopped working for all. It needs to be updated to use the new APIs. I will try and do that this week.

  • After investigating, I came to the conclusion that I will no longer be developing this plugin.

  • Pedro

    Super Sad Panda about development being halted. I’d absolutely get my own dev key if it meant getting this to work again.