如何使用twitter4j和风暴

时间:2013-01-09 03:55:06

标签: twitter twitter4j twitter-streaming-api

我使用twitter4j查询界面来过滤推文http://twitter4j.org/javadoc/twitter4j/Query.html。但https://github.com/nathanmarz/storm-starter/blob/master/src/jvm/storm/starter/spout/TwitterSampleSpout.java:43中的twitter spout使用queue.offer(status)。我没有对Status的引用,如何集成这些API来处理实时推文。

1 个答案:

答案 0 :(得分:0)

这是我们成功使用过滤推文的内容:

public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    queue = new LinkedBlockingQueue<Status>(1000);
    _collector = collector;
    StatusListener listener = new StatusListener() {

        public void onStatus(Status status) {
            queue.offer(status);
        }

        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        public void onTrackLimitationNotice(int i) {
        }

        public void onScrubGeo(long l, long l1) {
        }

        public void onException(Exception e) {
        }

    };
    TwitterStreamFactory fact = new TwitterStreamFactory(new ConfigurationBuilder().setUser(_username).setPassword(_pwd).build());
    _twitterStream = fact.getInstance();
    _twitterStream.addListener(listener);
    _twitterStream.filter(new FilterQuery().track(TERMS_TO_TRACK).setIncludeEntities(true));
}