Archive for September 15th, 2010
Processing + Arduino + Twitter + OAuth
WARNING: There’s a newer version of this code here: “Simple Processing Twitter”!
People who devise these spectacular security protocols and stuff really make it complicated to communicate to cool social networking sites. Yesterday I got carried away and ended up making a Processing sketch that could successfully connect to Twitter through its OAuth method. This is primarily for a project where Tweets are read, sent into Processing, which are then sent to the Arduino, which then broadcasts the message through its Xbee, and then the other robots pick up on the message. If the message is addressed to them, then they will parse it and do what it says. The first step though was to try and get the OAuth to work. Below is the link to the Processing code and some steps that I took that may help others.
1. Set up a Twitter application
Here is a screenshot of the settings that I used:

2. Open up the code and fill in the OAuth consumer information (line 131)
-
twitter.setOAuthConsumer("***", "***"); // consumer key, consumer secret
3. Uncomment the initTwitter() method call (and comment out the other twitter method calls) in void setup()
4. Open the sketch’s folder (keyboard shortcut: command-K). Open up url.text and go to that website. Copy the pin.
5. Enter the pin in pin.txt and press enter. For some reason there has to be a new line at the end, otherwise it won’t work
6. The code should now give you the access token and secret that you need. This should also be in tokens.txt now.
7. Take the tokens and put them into the code (line 238)
8. Comment out initTwitter() method call, uncomment connectTwitter(). You can also uncomment getSearchTweets too!
Hopefully those steps worked for you. It’s not totally automatic, with the whole copying and pasting of the tokens, but it seems to be the quickest and easiest way to get this done with Processing. Luckily you don’t have to do those steps all the time! Since it’s open source, maybe someone can improve on it!
If you find any bugs or have improvements, be sure to leave a comment or notify me! Happy tweeting!

This is the screenie when it worked! Woohoo!

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. GO OPEN SOURCE!





