Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter twitter4j stream

I'm trying to filter my twitter4j stream with the following code :

    TwitterStream twitterStream = getTwitterStreamInstance();

    // Listener
    twitterStream.addListener(listener);

    // Filter
    FilterQuery filtre = new FilterQuery();
    String[] keywordsArray = { "iphone", "samsung" };
    filtre.track(keywordsArray);
    twitterStream.filter(filtre);

    // Listening
    twitterStream.sample();

But the result is, for example :

27/59 - "Taking a risk over something only means that you want it more than anything"
28/63 - The more attractive you are, the more awkward I am.
29/64 - the thing about pain is that it demands to be felt

And I don't recover the keywords I want to follow, where is the problem ?

like image 728
Apaachee Avatar asked May 21 '13 08:05

Apaachee


1 Answers

You don't need:

twitterStream.sample();

If you remove it, you should start seeing Tweets matching your filter query.

When you invoke filter your listener will receive filtered Tweets, however because you then invoke sample you are effectively replacing the filtered-stream your listener is receiving with the sample steam, which is a random selection Tweets.

So in other words call either sample or filter, but not both.

like image 60
Jonathan Avatar answered Oct 26 '22 04:10

Jonathan