2

Im new to twitter4j and processing.

I want to get the latest searched word from a list of words. I want this to be stored in the variable which will be queried. so:

PossibleWords[] ={"sad","happy","joyful"}

i would then want a string variable searchString to hold the latest tweeted tweet containing the word from the array. For example, if sad is tweeted just now, i want to get that tweet. So I need to test if any of the words from the array is in the latest tweeted words.

conceptually, I understand this, but any one have any suggestions on programming this? This in processing using twitter4j 3

Pro-grammer
  • 862
  • 3
  • 15
  • 41

2 Answers2

1

You should use the Twitter Streaming API, look at the code block that I pasted below:

     private void GetTweetsByKeywords()
     {

        TwitterStream twitterStream = new TwitterStreamFactory(config).getInstance();

                StatusListener statusListener = new StatusListener() {
                    private int count = 0;
                    private long originalTweetId = 0;

                    @Override
                        public void onStatus(Status status) {

                        // Here do whatever you want with the status object that is the       
                         //  tweet you got

                        } //end of the onStatus()
         }; //end of the listener

         FilterQuery fq = new FilterQuery();

         String keywords[] = {"sad","happy","joyful"};

         fq.track(keywords);


         twitterStream.addListener(statusListener);
         twitterStream.filter(fq);
    }
makes
  • 6,438
  • 3
  • 40
  • 58
mgokhanbakal
  • 1,679
  • 1
  • 20
  • 26
  • Thanks for this, it is much appreciated, i have used this but i get an error, could you look at it? http://stackoverflow.com/questions/20332659/processing-twitter4j-no-files-added-to-sketch – Pro-grammer Dec 05 '13 at 13:39
0

Have you considered using the Twitter streaming API? This allows you to pass in up to 400 keywords and get a real time stream of tweets with any of those words in it. For example in twitter for J see here:

twitter4j - access tweet information from Streaming API

Replace the line

 String keywords[] = {"France", "Germany"};

with

 String keywords[] = {"sad","happy","joyful"};

and you should get a stream of tweets.

Community
  • 1
  • 1
DavidC
  • 1,842
  • 1
  • 18
  • 32
  • Thanks for this, it is much appreciated, i have used this but i get an error, could you look at it? http://stackoverflow.com/questions/20332659/processing-twitter4j-no-files-added-to-sketch – Pro-grammer Dec 05 '13 at 13:43