问题
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 ?
回答1:
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.
来源:https://stackoverflow.com/questions/16665683/filter-twitter4j-stream