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:

3 thoughts on “The OAuth Tweeting Doorbell

Leave a Reply to Ewan McDougall Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>