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?

Olayinka
  • 2,813
  • 2
  • 25
  • 43
  • You might want to take a look at Spring XD (or at least Spring Integration) instead of rolling your own. – M. Deinum May 15 '15 at 12:49

1 Answers1

5

It is possible. You first need to obtain a connection. The code would look something like this:

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));
manntonn
  • 310
  • 1
  • 5
  • 14