how to update an old twitter search api code if i havnt used it for three years

edited November 2017 in Library Questions

hi all,

I really need help. I haven't used processing for three years and my mind is totally blank on how to update this old code i wrote and make it run on my new computer and with whatever changes processing and Twitter may have made.

I wrote this code so that it would search and stream tweets that contained a specific phrase and play those stream tweets on a screen.

I have the old code but it won't run anymore

it could be something very basic like i am missing a library but it feels like more.

I could really really use some help. and would super interested in even emailing someone about it if anyone would be down (i need to get this up and running for porject and i am in tight space)

here is my old code

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

    Twitter twitter;
    String searchString = "Rest In Peace";
    List<Status> tweets;

    int currentTweet;
    int offsetx, offsety;
    PFont f;
    float x;
    void setup()
    {
       f = loadFont("HelveticaNeue-Bold-90.vlw");
        size(displayWidth, displayHeight);
       offsetx=(displayWidth-10);
     offsety=(displayHeight-10);
    ;

        ConfigurationBuilder cb = new ConfigurationBuilder();


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

        twitter = tf.getInstance();

        getNewTweets();

        currentTweet = 0;


    }

    void draw()
    {
        background(255);
        textAlign (CENTER, TOP);
         textFont(f, 90);

        currentTweet = currentTweet + 1;

        if (currentTweet >= tweets.size())
        {
     print("getting new tweets");
     currentTweet = 0;
         getNewTweets();
       }

     Status status = tweets.get(currentTweet);

        fill(0);
        text(status.getText(), 0, 400, displayWidth, displayHeight);

        delay(8000);
    }


    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);
        }


        //going to print out new tweets
        int curt = 0;
        for(int i=0; i< tweets.size(); i++){

         Status status = tweets.get(curt);
         print(status.getText() + "\n");
         curt = curt + 1;
        }

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

            println("Updated Tweets"); 

            delay(30000);
        }
    }

and this is the error that i am getting

Failed to search tweets: Connection refused (Connection refused)

Could not run the sketch (Target VM failed to initialize).

For more information, read revisions.txt and Help → Troubleshooting.

Answers

Sign In or Register to comment.