Monthly Archives: September 2010

The OAuth Tweeting Doorbell

After threatening to disable standard authentication for a long time, Twitter finally disabled it just after my doorbell had started working. As a result, the doorbell stopped tweeting which (as I’m sure you can imagine) reduced my technological standing to that of a caveman. Something had to be done. So, my doorbell now connects to Twitter using OAuth authentication.

OAuth relies upon the user approving the use of a service or application via Twitter, and logging in with Twitter’s authentication mechanism to do this. This results in no passwords or usernames being sent with each subsequent connection which is good news. However, OAuth is not a trivial thing to implement.

Fortunately, Marcel Molina has authored a tool called twurl which serves as a replacement for curl, but specifically for Twitter and using OAuth authentication. Setting it up is pretty easy. Since it’s a ruby gem, installation is as simple as it could really be. On the machine that will be sending the tweets, open up the terminal and enter:

sudo gem install twurl

…then enter your password when prompted. Twurl is now installed! To authorise it though, we need to create an application entry on Twitter, so that we get a Key and Password. Log in to Twitter as the account that will be sending the tweets (not your normal account). Click the “API” link at the bottom of the page, then choose Register an App to get started. Fill out the details however you like – we are not intending to distribute this app to third parties – but do make sure that the “Application Type” is set to “Client” (twurl is not browser based), and Default Access Type is set to “Read & Write” (we intend to actually send direct messages). You should get something back that looks similar to the screenshot below.

The important things on this page are the Consumer Key and the Consumer Secret. Note these down, and run the following command in the terminal, replacing the values as appropriate.

twurl authorize --consumer-key CONSUMERKEY --consumer-secret CONSUMERSECRET

This command will generate a URL, which you can copy and paste into a browser. The terminal is waiting on a PIN from you, which you can get by visiting the URL, and clicking “Allow”. Copy the PIN into the terminal and press return, and (hopefully!) the message “Authorization Successful” will display. Twurl is now authorised to tweet on that user’s behalf.

We just need to modify our AppleScript a little to use twurl instead of curl:

on dm(recipient, msg)
	set scriptpath to "twurl -d 'screen_name=" & recipient & "&text=" & msg & "' /1/direct_messages/new.xml"
	do shell script (scriptpath)
end dm

You can download the AppleScript below.


I have seriously run out of impressive things my doorbell can do now…

Related posts:

CSS3 TextMate Bundle

I’ve combined the previous CSS3 TextMate Snippets into a bundle, which was a lot easier to do than I thought it would be. I’ll detail how to make your own in a future post.

The bundle I’ve created plays nicely with existing CSS snippets that are bundled with TextMate. I’ve included:

  • background horizontal linear gradient
  • background vertical linear gradient
  • border-radius bottom left
  • border-radius bottom right
  • border-radius top left
  • border-radius top right
  • border-radius
  • box-shadow

You can download the bundle below.

Download CSS3.tmbundle.

Let me know how you get on, and if there any other properties you’d like me to add.