« Comment on Blogs with your Twitter Account | Main | Open Melody: Movable Type Forked »

Share Blog Comments on Twitter (plus OAuth Support)

Twitter Commenters is a plugin for Movable Type that enables commenters to sign-in and comment on your blog using their Twitter account. Versions 2 includes support for Twitter's OAuth authorization system and enables commenters to automatically share their comments to their Twitter stream.

Basic Auth (default):

OAuth:

Twitter comment authentication works like other auth methods in MT -- once you have installed the plugin you can enable Twitter as one of the auth options, as shown in the image above.

How It Works - Basic Auth

When the user enters their Twitter username and password in the form (shown above), the plugin submits those to the Twitter API to verfiy the credentials. If verified, the user can then post comments using their Twitter account. Their Twitter 'display name' will be shown beside their comments, and their Twitter avatar (profile photo) will be imported and shown beside their comments (if userpics are enabled in your templates).

Note that users' Twitter passwords are not stored in the MT database. An upcoming version of this plugin will enable Twitter's new OAuth support, in which case passwords would never be sent to MT at all. That version will like have an option for commenters to cc. their comments to their Twitter account. Stay tuned.

How It Works - OAuth

New in Version 2.0, you can optionally enable Twitter's new OAuth authorization system. With OAuth, user never have to submit their password info to your server. Instead, they click a "sign in with Twitter" button and they are taken to a page on Twitter.com asking them to authorize the application (see image above). One they click "Allow" they are returned to your site and they then post comments using their Twitter account. As with basic auth, their Twitter 'display name ' will be used as well as their Twitter avatar (profile photo).

Share Comments on Twitter

A new feature in version 2.0, only supported via OAuth, enables commenters to optionally share their comment to their Twitter stream. All they have to do is click a checkbox, no need to re-authorize or enter Twitter account info.

Try it Now

MT Hacks has the new OAuth method enabled. Try it now:

Click here to login with your Twitter account. After logging in, you will be returned to this entry, and you can leave a comment below.

Requirements

  • Net::Twitter 2.07 perl module (included with plugin) (note: do not upgrade to version 2.9+ of this module)
  • Net::Twitter::OAuth perl module (included with plugin)
  • Net::OAuth perl module (included with plugin)
  • Net::OAuth::Simple perl module (included with plugin)
  • JSON::Any perl (included with plugin)

Note: Net::Twitter requires newer versions of the libwww-perl collection of Perl modules. I am not sure what the minimum version required is, but on my server, I had to upgrade in order to get Net::Twitter to work. So if you get strange errors, try installing the latest version in your 'extlib' directory of your MT. Update: A common error message is: "Can't locate object method "default_header" via package "LWP::UserAgent" -- if you see this error, this the problem.

Download Twitter Commenters

Download Now
Downloads: 269

Installation

  1. Upload the contents of the 'plugins' folder to the 'plugins' directory for your MT install.
  2. Upload the contents of the 'mt-static' folder to your 'mt-static' directory.
  3. For each blog you want to enable, go to Preferences > Registration and check the box for 'Twitter'.

Enabling Twitter OAuth

Unfortunately, this is not as easy as it could be, maybe Twitter will make it easier in future. To set this up you need to create an Application on Twitter:

  1. While logged in to your Twitter account, go to http://twitter.com/oauth_clients/new.
  2. Fill out the form on that page:
    • Give it a unique name and description.
    • For 'Application Website', enter http://mt-hacks.com/twittercommenters.html. For 'Organization', enter MT Hacks.
    • For 'Website' enter http://mt-hacks.com.
    • For 'Application Type' choose 'Browser'.
    • For 'Callback URL' enter the full URL to your comments script followed by '?__mode=login_external&key=Twitter'. Example: http://www.domain.com/cgi-bin/mt/mt-comments.cgi?__mode=login_external&key=Twitter
    • For 'Default Access type' choose 'Read & Write'.
    • Check the box for 'Yes, use Twitter for login'
    • Hit the 'Save' button.
  3. After saving the application, you should now see a screen with a 'Consumer key' and 'Consumer secret'. Copy those to the system plugin Settings (System Overview > Plugins > Twitter Commenters > Settings). and save the plugin settings.
  4. To enable the share comment on Twitter option, add the <mt:TwitterShareCommentOption> tag below the comment text part of your comment form. This will display a checkbox option to people logged in via Twitter OAuth.
  5. Rebuild your entry pages and test it out

As always, feedback is appreciated.

Follow @mthacks on Twitter for updates and other MT and Twitter hacks.

Rate this entry:

  • Currently 5/5
  • 1
  • 2
  • 3
  • 4
  • 5
Rating: 5/5 (2 votes cast). Powered by the Ajax Rating plugin.

Comments (39)

Just an example of a blog comment shared on Twitter via Oauth

Update: Here is the tweet.

Mark

I'm getting the following error:
" Can't locate object method "default_header" via package "LWP::UserAgent" "

Any ideas?

Michele

I'm getting the same error as Michele.

Can't locate object method "default_header" via package "LWP::UserAgent"

Weird, it posted that twice... and NOW I see you've actually mentioned this error. I skipped that part apparently.

@mneylon: that exact error is mentioned in the the post (with solution) ;)

Upgraded the perl modules server-wide.Still getting the error :(

LWP::UserAgent v 2.032 (Jun 2004) is required for Net::Twitter. I've made the appropriate change to Makefile.PL. A Net::Twitter maintenance release will be uploaded to CPAN soon.

Mark will this or could this (eventuall) work for user entries? For example if you are running the Community Solution and let users post new entries - could those new entries also be sent to the user's Twitter account and/or could they log into MT with the Twitter info?

My LWP::UserAgent on the shared server I'm using is out of date. I've used CPanel to invoke CPAN to update LWP::UserAgent to the latest version, which it's done successfully, and installed the modules in /home/myusername/perl. However, I don't have read access to this directory, only write and execute access, so I can't copy the files to the extlib directory.

I've tried adding the the module location to mt.cgi, mt-cp.cgi and twitter.pm using 'use lib /home/myusername/perl'. However, I still get the standard 'can't locate object method' error. Is there a way to get the plug-in to look in the right-place for the correct version of LWP::UserAgent? Would a symbolic link somewhere work (created by a one-off cron job since I don't have command line access on the server)?

Yves Author Profile Page:

Hi Marc,

the cronjob, polling my Action Streams, is throwing errors since I installed your plugin:

"my" variable $key masks earlier declaration in same scope at [yadda-yadda]/cgi-bin/mt/plugins/TwitterCommenters/TwitterCommenters.pl line 124.

Do I have to take this serious?

Anonymous:

I've managed to upgrade LWP::UserAgent and install it in extlib now. However, what I get when I try to sign in with Twitter is "Can't call method "permalink" on an undefined value". Any ideas?

Looking forward to getting this work, because it promises so much!

Jamie M. Slaton:

Hey I'm Jamie M. Slaton resident of South Carolina and my interests are fashion and law educations. I'm taking part in a fight against crime. There are many crimes that are happening nowadays and I think it's better to make a movement out of this. We need to start a rundown of what's going on in our country. For instance, there are corrupt government officials that are letting criminals out of bars. It should stop and most probably end these wrong deeds. Even though these culprits escaped, can easily find out what and where they can be found. We just need to search for criminal records of these escaped convicts. So if anyone interested to fight these things, we should start now.

twitter is a good appplication i used it and found good to reach owner

Rob:

I've got a bit further now. The 'permalink' error stems from the fact I'm using MT Pro. The Twitter.pm library seems to want a CGI parameter that doesn't exist with the mt-cp.cgi script - 'return-to' - when it really wants 'static'. I edited Twitter.pm to use that instead.

All works fine after that as far as I can see with regards to authentication at Twitter. However, the value of 'static' is URL encoded so won't return the user to the right location. However, by invoking url_decode() (and 'using' the appropriate library at the beginning of Twitter.pm) before submitting it to the return_to cookie, you can get that bit to work fine.

The final problem is trickier - for some reason, no user ends up being created in the user database, even though the plug-in correctly grabs the Twitter pic, etc. Equally, the wrong cookies appear to be used - the old style, non-community cookies for name, etc, rather than the single 'mt_blog_1' cookie. That means the 'authentication_type' cookie also doesn't get wiped on logout, meaning that if you log in with Twitter, you don't get signed in and you always get the 'Share this comment on Twitter' option, even if you sign out and sign in with a different authentication method.

No idea how to fix it and I've been experimenting a lot!

Anonymous:

I have the same problem as Rob above - getting an error about not being able to call the permalink method.

I looked at the code and found the follow lines:
if (!$return_to) {
my $entry = MT->model('entry')->load($entry_id) if $entry_id;
$return_to = $entry->permalink . '#_login';
}

The problem here is that if #entry_id does not exist, $entry does not exist on the following line.

I changed it to: if ( !$return_to && $entry_id ) and it logged me in, but put me in the wrong place.

I also noticed that it does not add me to the database, but I find that this is true for other login methods too.

thanks
Andrew

Having the same problem as the other fellows, apparently -- Twitter comments don't appear to work on an MT Pro install. Any idea if this is something you can fix? (Or be bribed to fix? :))

Mark Author Profile Page:

Thanks Anil, and thank you Rob all the detailed info -- very helpful stuff.

It seems I need to test the plugin against MT Pro and make some tweaks to accommodate some the peculiarities of the mt-cp script. Stay tuned for an update.

Thanks for the new release - hopefully it will work on my install now :)

if you get a "JSON::Any version 1.19 required--this is only version 1.18" error, here is the likely fix:

This is probably happening because you have the Facebooker Commenters plugin installed, which includes JSON::Any 1.18 in its /extlib/ and this is conflicting with v1.19 that is included with Twitter Commenters.

To fix, go to:

/path/to/mt/plugins/FacebookCommenters/extlib/JSON/

and delete Any.pm

This won't break anything, as

Three installs, three lots of:

Can't locate object method "default_header" via package "LWP::UserAgent"

I've been trying to figure out how to install the missing Perl modules to extlib, but haven't been able to do so. Could you (or anyone?) perhaps give more detailed instructions, or provide the relevant files?

Sure, Adam. Its quite easy.

  • Got to http://search.cpan.org/dist/libwww-perl/.
  • Click the "Download" link.
  • Expand the zip archive
  • Upload the contents of the /lib/ folder to the 'extlib' directory of your MT install
  • Done
  • Thanks for the new release - hopefully it will work on my install now

    Testing commenting on blog of MT-HAcks and Twitter

    When will it be the otherway round, so people commenting on Twitter posted as blogcomment on the blog?
    Great to see this working.

    He can't see a logout button.....

    "Share Blog Comments on Twitter (plus OAuth Support)" is an excellent post. It is very informative. Thank you so much.

    This is a great plugin. I love it

    Interesting option to preview comments Twitter. I like very much. Also following the Google Wave embed discussion. Keep up the good work.

    sushi:

    site..= http://ezlaptop.com/?r=341553) visit this site and win a laptop today but type
    the whole site address..type
    including d num

    I’ve been wanting to spend more time on twitter to engage with my peers and individuals I want to learn from. This is exciting news!

    That is very good news for all bloggers round the world

    That is very good news for all bloggers round the world

    This is a test using Twitter Connect.

    Thanks a lot.

    thanks i have been searching on this article about twitter

    That is very good news

    Anonymous:

    For some who doesn't have a twitter,this does not make any relevance.

    Post a comment