Simple Processing Twitter

Posted by Erin, the RobotGrrl on Monday, February 21st, 2011

I created a really simple Processing and Twitter sketch to help a friend a few nights ago ^_^ It is based off of this previous code from the blog post “Processing + Arduino + Twitter + OAuth”. Here’s what changed:

- It now uses the Access Token that you can get from the Twitter App’s panel
- No more inserting PIN info into a file
- No Arduino clutter in the sketch
- Simple methods for posting, retrieving, and searching tweets.

You can probably do a lot more things with this too, thanks to Twitter4j.

Click to download SimpleProcessingTwitter.pde
Or view it on Github

If you use this code in one of your projects, let me know! It is cool to see what people make. :)



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

Posted in: Art, Programming, Projects.
Tags: , , , , , , , ,

36 Responses to “Simple Processing Twitter”

  1. Isaac Says:

    I’m working on my final project and I was using the older version… your code is going to help me a lot, thanks for sharing; your name will be attributed.

  2. Chris Spurgeon Says:

    This is GREAT! It works like a charm. Thanks so much!

  3. Blil Says:

    thanks, this was super helpful

  4. Brian Says:

    Thank you very much, this has solved so many problems.

    However, the code is not returning any tweets from the search tweets section… is there something I need to do in order for it to return results?

  5. chris Says:

    great tutorial, but i’m having a small issue of locating the access tokens. all I get now is an “access token URL” and there is no longer a button, like you mentioned in your Processing code and that has been present in the past on the Twitter app settings page. How do I get the Token from the URL?

    Thanks and awesome site!

  6. chris Says:

    Ignore that last comment. When i set up my App, it was at twitter.com/apps which has very little options.

    dev.twitter.com/apps gets you to where you can locate the token information.

    Still not getting it to work, as it’s throws an exception:
    Send tweet: TwitterException{exceptionCode=[15bb6564-00e4d62e 15bb6564-00e4d603], statusCode=-1, retryAfter=0, rateLimitStatus=null, version=2.1.5-SNAPSHOT(build: d372a51b9b419cbd73d416474f4a855f3e889507)} Status code: -1

    at least i’m moving in the right direction. i bet it’s an issue with my firewall.

    thanks!

  7. finoradin Says:

    thanks! as usual u = win.

  8. nick Says:

    THANK YOU ROBOT GRRL!!!!
    Twitter4j is a fantastic library but it took your human-readable example for me to understand how to properly implement it. For a school project I had an idea for a Morse-Code-To-Twitter machine, also using the Morse Encoder Library for Arduino. My only challenge was figuring out how to collect the “chars” into strings, reading in processing, displaying messages and then sending to twitter. Thanks to all the time you saved me after killing almost an entire day trying to implement the 4J library, I had time left to create a backspace and handy “send to twitter” button right on my circuit board. Once I finish everything and clean up the code I’ll make it available so other people can join the #sentWithMorse twitter stream thanks to YOU!!!

    you can see it finally operational here:
    http://www.youtube.com/watch?v=4r8A4OWSvZQ&feature=player_profilepage

  9. Simple Processing for Twitter | Visualizing Egypt Says:

    [...] some handy Processing code to facilitate Twitter access from within a sketch. It can be found at http://robotgrrl.com/blog/2011/02/21/simple-processing-twitter/. I have successfully used it to post a tweet to my personal account. This entry was posted in [...]

  10. Mid Term Report | Visualizing Egypt Says:

    [...] tweets as an alternative to accessing the API via a web browser (as I did initially). I modified Robotgrrl’s Simple Twitter for Processing program to gather more tweets, limit them to English, and then write the username, date, and tweet [...]

  11. √isualpaco Says:

    Hello,
    I would like to try your very interesting sketch.
    I get a problem of a missing class:
    “Cannot find a class or type named User”.
    I put the twitter4j.jar file into Processing/libraries
    I’m indeed missing some basic thing but at the moment I cannot really find a solution to the problem.
    Any suggestion?
    Thank you much for your amazing work!!!
    √p

  12. Final Reflection | Visualizing Egypt Says:

    [...] Processing Twitter”, accessed May 25th, 2011, http://robotgrrl.com/blog/2011/02/21/simple-processing-twitter/ This code allows direct access to the Twitter API from within a Processing [...]

  13. JC Says:

    Hey there,
    Thanks a million for your code. It’s very easy to use and do things quickly.

    One thing though: I’m listening to a hashtag by triggering a search for it every 5 seconds.
    I take the first tweet in the list of tweets that’s returned and compare it to the previous “latest tweet”.

    Not sure it’s the best way to go about this…

    Anyway. The search doesn’t seem to be retrieving all tweets containing the hashtag (maybe only 1 out of 5).

    Or are the returned tweets not in chronological order?

    Anyone got an idea?

    thanks again!

  14. JC Says:

    OK, I figured out the problem.

    Twitter has an algorithm that chooses the most relevant tweets and organises them in a list.

    When doing a search on twitter, there are 3 kinds of lists of results available: top, all and with links.

    With the current implementation of the code here, doing a search only returns the most relevant tweets (the “all” list).

    Is there a way we could get the “top” list? i.e. every single tweet that comes out?

    thanks!

  15. guru chans Says:

    Thanks for sharing that link but alas it seems to be down? Anybody have a mirror?

  16. Andrew O'Malley Says:

    This is great, thanks so much!

    By putting the twitter4j.jar file in a folder called “code” in my Processing sketch folder, this works great for searching tweets.

    I can’t seem to post a tweet, however, but my application is listed as “read only” on Twitter’s dev site, so I assume this is the problem, not the Processing side.

    Is there documentation for this library anywhere? Perhaps I have missed the obvious?

    Thanks again, will share my documented project when it’s done :)

    ao.

  17. Jon Says:

    Hi thanks for posting this. Its nice to have a barebones example of Processing to Twitter. I’ve set up an application on Twitter and tried inputting my credentials into your code but I’m getting a Status code: 401 when I try to run your code. Have you or anyone else experienced the same problem? Thanks again.

  18. Erin, the RobotGrrl Says:

    Have to be careful about the Read-Only part! http://farm7.static.flickr.com/6149/5991617997_cd96913c77_b.jpg

    That might be where the 401 error is coming from

    The annoying thing though is that you have to make sure you change the permissions *before* generating your token. It seems as though there is no way to regenerate the token through the dev.twitter site after it was already generated -.-;

  19. Jon Says:

    Yup that was the problem and you’re right that is annoying that you have to do it in that specific order. Thanks so much for the tip. I’m all set!

  20. Marcos Says:

    hey there… worked like a charm. just had to comment out the User[] friends; bit.

    Beware, world. I can send tweets from my processing apps.

  21. Julia Says:

    I have tested to post a feed through processing and it worked!
    Is there a way to view the latest feeds on the arduino lcd screen using this???

    Is there an example code available on online?

  22. Kim Says:

    Thx for sharing this! I got it to work to post the given tweet to my Twitter account. I am new to Processing and wanted to see an example that would work right away. So this was perfect. But I noticed that you have one twitter4j.jar file but the Twitter4J site’s download consist of multiple jar files in different folders. Which one of them is the single jar file you are using?

  23. Kein Says:

    Thank you so much for posting this. I REALLY appreciate!

  24. shields Says:

    Thank you for this. It’s hard to find a basic tutorial on this subject, let alone one that’s easy to understand for the beginner. This has given me a great starting point from which to build on. Bravo.

  25. Rob Says:

    Hi,
    can you briefly explain how to use the code? Sorry I am new to this.

    thanks for your time and for the motivation, this made me go out and buy an Arduino, Ethernet sheild, and a couple other things. I just need a little help getting all of this to work, I am sure things will click soon.

    best wishes,

    Rob

  26. Gauthier Says:

    Thanks but I have test your code for send tweet and It’s very good. But When I use twitter4j for send image with twitpic or other… it doesn’t work.
    So I propose you an other library for processing: processing-http
    https://github.com/francisli/processing-http/wiki
    It’s so easy to build. You must try it!

    Thank you!

  27. Fraser Says:

    Hi RobotGrrl, Love your work; but must take so much time and effort! I tried Using our code( I got ConsumerKey And Secret, And i also Got the AccessToken And secret. I put them in the required Gaps And i got an error in the Arduino Coding enviroment saying ” expected unqualified-id before ‘private’ ” It also highlights the accessTokenSecret Line
    (“static String AccessTokenSecret = “**************”;”) I’m Pretty new to the whole arduino thing and i have done basic coding before so im pretty stumped as to whats causing the problem and how to fix it. I understand that wher it says “Expected unqualified-id” There is something that it thinks should be there and that when it says “before ‘private’ ” I realise that it wants the ‘thing’ infront of ‘private’ but the thing is i don’t know what it is referring to. Any help would be appreciated immensely.
    If anyone has a solution, you can email me at fraserhoenes@yahoo.co.uk.

    Many Thanks,

    A fellow coder :)

  28. Fraser Says:

    *Your

  29. twitter+processing_weeklong1 | week_long Says:

    [...] http://robotgrrl.com/blog/2011/02/21/simple-processing-twitter/ [...]

  30. Final Code | DAT302 Everyware Says:

    [...] The code could be tidier, but for now this is satisfactory.The twitter code we used came from robotgrrl.comA TL;DR of the code is as [...]

  31. John Says:

    Thanks so much for posting this code!

    I’ve got it half working. And it looks like its the opposite problem that others are having. I can tweet from inside Processing but can’t seem to grab the tweets from my feed (other than the posts from Processing).

    I suspect it may be my settings from the “Request URI” and “Request query” areas in the Request Settings window in the Developers area. Anyone know if I’m on the right track for narrowing the problem down?

    I’ll be sure to link to my video using this snippet when I’m done.

  32. Pelling Lab.net | Online 6-Well Plate … (ahem …. Cells with a Twitter Account) – Progress Says:

    [...] on the same Processing code and Arduino hardware I’ve been tinkering with (many thanks to RobotGrrl and Ashley Hughes for some very helpful [...]

  33. hilser Says:

    Hi,

    Thanks so much for easy to read instructions, code and the sketch! so many others forget to even say simple things like “set up a developer account”
    best of luck with your own projects!

  34. TweeterGrateful is getting closer! | i-hilser Says:

    [...] http://robotgrrl.com/blog/2011/02/21/simple-processing-twitter/comment-page-1/#comment-329527 [...]

  35. Ben Says:

    @John, did you ever find a solution to this? I am having the same problem. :(

    Great work by the way, best and easiest to understand example on the web

  36. Paddy Says:

    RobotGrrl thanks for the post… A few questions you might be able to help with or anyone else… What version of Twitter4J are you using for this? I can’t get it working on Twitter4J.3.0.3..
    says… function setRpp(int) does not exist…
    Changed it to count then
    cannot find class or type named “Tweet”
    Any idea?
    Thanks in advance…

Leave a Reply