Loading...
Logo
Processing Forum
Hi there,

I've been trying to use the Tweet Stream library for processing to track keywords that are tweeted by a specific user. Is this possible and am I using the right library? I'm a bit new to Processing so I'm sure it's a simple solution and I'm just not getting it. Any similar projects or any idea where to start with the code for this?

Thanks

Replies(2)

  I just got twitter4j, http://twitter4j.org/en/index.html ,  working and it seemed more straight forward to me. You'll have to sign up for the consumer key and auth codes https://dev.twitter.com/ . Below is the ubiquitous "sandwich" example. Once you download the twitter4j-2.2.0.zip unzip it and drag twitter4j-core-2.2.0.jar onto your sketch window. This adds the library (like import). 
  You can change:
   Query query = new Query("sandwich"); to Query query = new Query("<userName>"); and string match the t.getText . To find your text. Good Luck. -T
Copy code
  1. String consumerKey = "<your consumer key here>";
    String consumerSecret = "<your consumer secret here>";
    String accessToken = "<your access token here>";
    String accessSecret = "<your access secret here>";
    AccessToken token;


    Twitter myTwitter;

    void setup(){
       myTwitter = new TwitterFactory().getInstance();
       myTwitter.setOAuthConsumer(consumerKey, consumerSecret);
       token = new AccessToken(accessToken, accessSecret);
       myTwitter.setOAuthAccessToken(token);
     
      try{
        Query query = new Query("sandwich");
        query.setRpp(100);
        QueryResult result = myTwitter.search(query);
       
        ArrayList tweets = (ArrayList) result.getTweets();
       
        for(int i = 0;i<tweets.size();i++){
          Tweet t = (Tweet) tweets.get(i);
          String user = t.getFromUser();
          String msg = t.getText();
          Date d = t.getCreatedAt();
          println("Tweet by" + user + "at" + d + ": " + msg);
        }
      }
      catch(TwitterException te){
        println("couldn't connect: " +te);
      }
     
    }

    void draw(){
    }
Hey thanks so much. I have a lot of trouble getting the Twitter4J library into processing, I've tried what you suggested above and nothing happens but I will try again.

Also what is the access secret?? I have the consumer key, the consumer secret and the access token but no access secret.

I've got a Request Token Url and an Authorize Url but no access secret.

Any idea?