Using Twitter4j, how do I stream status updates authored or retweeted from one user?

326 Views Asked by At

I'm using Twitter4j's TwitterStream functionality to receive a stream of a heavily followed Twitter user's tweets, as follows:

...

private void initTwitterStream(AccessToken accessToken) {
    twitterStream = new TwitterStreamFactory().getInstance();
    twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
    twitterStream.setOAuthAccessToken(accessToken);
    twitterStream.addListener(createUserStreamListener());
    twitterStream.user("realDonaldTrump");
    logger.info("Listener initiated; listening for status updates.");
}

private UserStreamListener createUserStreamListener() {
    return new UserStreamAdapter() {

        public void onStatus(Status status) {
            log(status); // logs the tweet author and text
        }

    };
}

...

The problem I have is that I'm getting updates from anyone who has tagged this user in their tweet. For example:

16:22:02.150 [Twitter4J Async Dispatcher[0]] INFO  c.d.i.twitter.TwitterListenerService - Received status update from [foo1234]: @realDonaldTrump never trust a man's perspective of technology after he uses "cyber" as a noun

How do I configure Twitter4j so that I only receive tweets authored by this user, and not tweets that mention him?

0

There are 0 best solutions below