Greetings!

If any of the info on this website was useful for your projects or made your head spin with creative ideas, and you would like to share a token of your appreciation- a donation would be massively appreciated!

Your donation will go to my Robotics Fund, straight towards more sensors, actuators, books, and journeys. It takes a lot to continue building these robots, and I’m really thankful of everyone who helps encourage me along the way.


USD


CAD

“A wise robot once said to me through Serial.println- that robots teach us about ourselves.”

Simple Processing Twitter

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!

40 CommentsLeave a Comment


  • Isaac

    5 months ago

    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.

  • Chris Spurgeon

    5 months ago

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

  • Blil

    5 months ago

    thanks, this was super helpful

  • Brian

    5 months ago

    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?

  • chris

    5 months ago

    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!

  • chris

    5 months ago

    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!

  • finoradin

    5 months ago

    thanks! as usual u = win.

  • nick

    5 months ago

    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

  • √isualpaco

    5 months ago

    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

  • JC

    5 months ago

    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!

  • JC

    5 months ago

    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!

  • guru chans

    5 months ago

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

  • Andrew O'Malley

    5 months ago

    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.

  • Jon

    5 months ago

    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.

  • Erin, the RobotGrrl

    5 months ago

    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 -.-;

  • Jon

    5 months ago

    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!

  • Marcos

    5 months ago

    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.

  • Julia

    4 months ago

    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?

  • Kim

    4 months ago

    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?

  • Kein

    4 months ago

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

  • shields

    4 months ago

    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.

  • Rob

    3 months ago

    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

  • Gauthier

    3 months ago

    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!

  • Fraser

    2 months ago

    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 :)

  • Fraser

    2 months ago

    *Your

  • John

    2 months ago

    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.

  • hilser

    2 months ago

    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!

  • Ben

    2 months ago

    @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

  • Paddy

    2 months ago

    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…

  • Martin

    1 month ago

    Unable to get this working with either Processing 2 or 1.5, and twitter4j-3.
    My Twitter app is set to Read & Write and I have the Access Tokens.
    Any ideas?

  • Martin

    1 month ago

    Please ignore me!
    Got it working and updated Search query too

  • stu shapiro

    1 month ago

    Hey RobotGrrl :)

    thanks so much for this code. really awesome of you!

    I’m new to all of this obviously :p Do we just load up the code you wrote, replace the tokens and boom?

    when i checked the code after putting in my access and security info I got a huge error code when veryfiing.

    is there more to this than just opening this code and running it?

    SimpleProcessingTwitter:24: error: expected unqualified-id before ‘private’
    SimpleProcessingTwitter:28: error: expected constructor, destructor, or type conversion before ‘.’ token
    SimpleProcessingTwitter:29: error: expected constructor, destructor, or type conversion before ‘friends’
    SimpleProcessingTwitter:30: error: ‘Twitter’ does not name a type
    SimpleProcessingTwitter:31: error: ‘RequestToken’ does not name a type
    SimpleProcessingTwitter:32: error: expected unqualified-id before ‘[‘ token
    SimpleProcessingTwitter.pde: In function ‘void setup()’:
    SimpleProcessingTwitter:37: error: ‘size’ was not declared in this scope
    SimpleProcessingTwitter:38: error: ‘background’ was not declared in this scope
    SimpleProcessingTwitter.pde: In function ‘void draw()’:
    SimpleProcessingTwitter:48: error: ‘background’ was not declared in this scope
    SimpleProcessingTwitter.pde: In function ‘void connectTwitter()’:
    SimpleProcessingTwitter:56: error: ‘twitter’ was not declared in this scope
    SimpleProcessingTwitter:57: error: expected `;’ before ‘accessToken’
    SimpleProcessingTwitter:58: error: ‘accessToken’ was not declared in this scope
    SimpleProcessingTwitter.pde: In function ‘void sendTweet(String)’:
    SimpleProcessingTwitter:66: error: ‘Status’ was not declared in this scope
    SimpleProcessingTwitter:66: error: expected `;’ before ‘status’
    SimpleProcessingTwitter:67: error: ‘status’ was not declared in this scope
    SimpleProcessingTwitter:67: error: ‘println’ was not declared in this scope
    SimpleProcessingTwitter:68: error: expected type-specifier before ‘TwitterException’
    SimpleProcessingTwitter:68: error: exception handling disabled, use -fexceptions to enable
    SimpleProcessingTwitter:68: error: expected `)’ before ‘e’
    SimpleProcessingTwitter:68: error: expected `{‘ before ‘e’
    SimpleProcessingTwitter:68: error: ‘e’ was not declared in this scope
    SimpleProcessingTwitter:68: error: expected `;’ before ‘)’ token
    SimpleProcessingTwitter.pde: At global scope:
    SimpleProcessingTwitter:76: error: expected unqualified-id before ‘private’
    SimpleProcessingTwitter.pde: In function ‘void getTimeline()’:
    SimpleProcessingTwitter:85: error: ‘statuses’ was not declared in this scope
    SimpleProcessingTwitter:85: error: ‘twitter’ was not declared in this scope
    SimpleProcessingTwitter:86: error: expected type-specifier before ‘TwitterException’
    SimpleProcessingTwitter:86: error: expected `)’ before ‘e’
    SimpleProcessingTwitter:86: error: expected `{‘ before ‘e’
    SimpleProcessingTwitter:86: error: ‘e’ was not declared in this scope
    SimpleProcessingTwitter:86: error: expected `;’ before ‘)’ token
    SimpleProcessingTwitter:90: error: ‘statuses’ was not declared in this scope
    SimpleProcessingTwitter:91: error: ‘Status’ was not declared in this scope
    SimpleProcessingTwitter:91: error: expected `;’ before ‘status’
    SimpleProcessingTwitter:92: error: ‘status’ was not declared in this scope
    SimpleProcessingTwitter:92: error: ‘println’ was not declared in this scope
    SimpleProcessingTwitter.pde: In function ‘void getSearchTweets()’:
    SimpleProcessingTwitter:104: error: ‘Query’ was not declared in this scope
    SimpleProcessingTwitter:104: error: expected `;’ before ‘query’
    SimpleProcessingTwitter:105: error: ‘query’ was not declared in this scope
    SimpleProcessingTwitter:106: error: ‘QueryResult’ was not declared in this scope
    SimpleProcessingTwitter:106: error: expected `;’ before ‘result’
    SimpleProcessingTwitter:107: error: ‘ArrayList’ was not declared in this scope
    SimpleProcessingTwitter:107: error: expected `;’ before ‘tweets’
    SimpleProcessingTwitter:109: error: ‘tweets’ was not declared in this scope
    SimpleProcessingTwitter:110: error: ‘Tweet’ was not declared in this scope
    SimpleProcessingTwitter:110: error: expected `;’ before ‘t’
    SimpleProcessingTwitter:111: error: ‘t’ was not declared in this scope
    SimpleProcessingTwitter:113: error: ‘Date’ was not declared in this scope
    SimpleProcessingTwitter:113: error: expected `;’ before ‘d’
    SimpleProcessingTwitter:114: error: ‘theSearchTweets’ was not declared in this scope
    SimpleProcessingTwitter:116: error: ‘println’ was not declared in this scope
    SimpleProcessingTwitter:119: error: expected type-specifier before ‘TwitterException’
    SimpleProcessingTwitter:119: error: expected `)’ before ‘e’
    SimpleProcessingTwitter:119: error: expected `{‘ before ‘e’
    SimpleProcessingTwitter:119: error: ‘e’ was not declared in this scope
    SimpleProcessingTwitter:119: error: expected `;’ before ‘)’ token

Trackbacks for this post

  1. Simple Processing for Twitter | Visualizing Egypt
  2. Mid Term Report | Visualizing Egypt
  3. Final Reflection | Visualizing Egypt
  4. twitter+processing_weeklong1 | week_long
  5. Final Code | DAT302 Everyware
  6. Pelling Lab.net | Online 6-Well Plate … (ahem …. Cells with a Twitter Account) – Progress
  7. TweeterGrateful is getting closer! | i-hilser
  8. Processing – Twitter using Twitter4j | MA in Museum Experience

Leave a CommentPlease be polite. We appreciate that.

Your Comment