We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Twitter, Processing and Twitter 4J.
Page Index Toggle Pages: 1
Twitter, Processing and Twitter 4J. (Read 2298 times)
Twitter, Processing and Twitter 4J.
Jul 12th, 2009, 3:05pm
 
Hi,

I´m new to Processing and to Java. I was wondering if you could help me out.

Using the Twitter 4J Library I´ve managed to get the code to access my updates, but it only does this once while my sketch is running. What I need to happen is for it to automatically check for new updates. In other words, if I post to my twitter account, the processing sketch show update also and print it the new status.


The goal is to have a sketch that prints all the new updates to a twitter account.


The only way I´ve managed to do this is by creating a new object every few moments which seriously slows down the sketch:



void draw () {

 background(255);    
 fill(0);
 textFont(theFont);

 
 y = y - 1;










       //this code is used to access the status. There is a problem with it as it creates an object every time it runs.



        if (y == -51) {
 
             twitter = new Twitter(username,password);
             //java.util.List statuses = twitter.getUserTimeline();
                       
                                 try{statuses = twitter.getUserTimeline(); }

                                 catch( TwitterException e) {println(e.getStatusCode());}
 
                                 Status status = (Status)statuses.get(0);
                                 mess = (status.getUser().getName() + ":  " + status.getText() + " : "  + status.getCreatedAt());
 
 
                                y = 0;
 
                        }

// this checks to see if the new update is the same as the old one.

           if  (mess.equals(message[0]))        { //println("equal");
         moveDown = false; }

 
                     else{
   
                             println("new post!");
                             message[w] = mess;
                             w = w+1;
                             if (w == 11){w = 0; }
                             moveDown = true;
                           
                          }
 
 


Any help?



Re: Twitter, Processing and Twitter 4J.
Reply #1 - Jul 14th, 2009, 2:57am
 
use multithreads and call it every 5 minutes or so. check twitter api how to avoid hammering bans.

insta-updates require constant recalls, which would probably get your connection banned after a while. all twitter client applications have a timer for when to check for updates. usually is couple minutes.
Re: Twitter, Processing and Twitter 4J.
Reply #2 - Jul 14th, 2009, 12:19pm
 
Thanks so much for the info! I´m going to look into how to do that ('cause I´m not exactly sure).

In the meantime, if anyone feels like posting some sample code of how one would do a multithread as described above, that would be fantastic. Smiley
Re: Twitter, Processing and Twitter 4J.
Reply #3 - Jul 15th, 2009, 9:50am
 
you have to implement runnable interface. which might sound scary if you're not a seasoned coder, but it's not really that complicated once you take a look at similar code.

this thread is a nice place to start:
http://processing.org/discourse/yabb2/?num=1204990614
Page Index Toggle Pages: 1