Filter twitter4j stream

余生长醉 提交于 2020-05-26 10:25:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!