2

I am working on a project where I have to gather users' live stream from social networks (Twitter, Facebook etc.). I want to use Twitter Users Streams Api to get live tweet updates from registered users, analyze these updates and then store the result in a database.

I am using the spring framework to register users and I'd to register a thread listener to get the live tweets. Is this possible with the spring framework? If so, how can I go about it, I can't find useful information with Google search. If not, what is the best way around?

4

1 に答える 1

5

可能です。最初に接続を取得する必要があります。コードは次のようになります。

StreamListener listener = new StreamListener() {
        @Override
        public void onTweet(Tweet tweet) {
            logger.info("new tweet coming in");
        }

        @Override
        public void onDelete(StreamDeleteEvent deleteEvent) {
                logger.debug("delete event called on stream"););
        }

        @Override
        public void onLimit(int numberOfLimitedTweets) {
                logger.debug("stream is being track limited");
        }

        @Override
        public void onWarning(StreamWarningEvent warningEvent) {
                logger.debug("warning from twitter");
            }
        }
    };
    Connection<Twitter> connection = getCurrentConnection();
    // this will open the stream
    Stream stream =   connection.getApi().streamingOperations()
            .filter("filter", Arrays.asList(listener));
于 2015-05-15T12:45:33.477 に答える