筛选twitter4j流 [英] Filter twitter4j stream
问题描述
我正在尝试使用以下代码过滤我的twitter4j流:
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();
但是结果例如:
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 ?
推荐答案
您不需要:
twitterStream.sample();
如果将其删除,则应该开始看到与您的过滤器查询相匹配的推文.
If you remove it, you should start seeing Tweets matching your filter query.
调用filter
时,侦听器将收到过滤的Tweets,但是,由于随后调用sample
,您将有效地将侦听器正在接收的过滤流替换为样本流,这是随机选择的Tweets.
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.
因此换句话说,调用 sample
或
So in other words call either sample
or filter
, but not both.
这篇关于筛选twitter4j流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!