twitter & processing

edited May 2014 in Library Questions

Hi there, i'm trying to edit this code (twitter4j library) in order to get more than 15 tweets, and to stop the loop thing (the 15 tweets appear over ad over again). i want to get more tweets, and don't want them to appear again... for it to work, you have to insert the appi twitter keys. Could someone hel me?

import twitter4j.conf.*;
import twitter4j.*;
import twitter4j.auth.*;
import twitter4j.api.*;
import java.util.*;

Twitter twitter;
String searchString = "design";
List<Status> tweets;

int currentTweet;

void setup()
{
    size(1920,1200);
    background(0);
    smooth();

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey("************consumerkeyhere************");
    cb.setOAuthConsumerSecret("************consumersecrethere************");
    cb.setOAuthAccessToken("************accesstokenhere************");
    cb.setOAuthAccessTokenSecret("************accesstokensecrethere************");

    TwitterFactory tf = new TwitterFactory(cb.build());

    twitter = tf.getInstance();

    getNewTweets();

    currentTweet = 0;

    thread("refreshTweets");
}

void draw()
{
    fill(0, 40);

    currentTweet = currentTweet + 1;

    if (currentTweet >= tweets.size())
    {
        currentTweet = 0;
    }

    Status status = tweets.get(currentTweet);

    colorMode(HSB, 60);
    fill(status.getCreatedAt().getMinutes(),100,100);
    textSize(random(10,30));
    text(status.getText(), random(width-300), random(height-200), 300, 200);

    delay(2000);
}

void getNewTweets()
{
    try 
    {
        Query query = new Query(searchString);

        QueryResult result = twitter.search(query);

        tweets = result.getTweets();
    } 
    catch (TwitterException te) 
    {
        System.out.println("Failed to search tweets: " + te.getMessage());
        System.exit(-1);
    } 
}

void refreshTweets()
{
    while (true)
    {
        getNewTweets();

        println("Updated Tweets"); 

        delay(30000);
    }
}
Sign In or Register to comment.