Search code examples
javatwittertwitter4j

get count of mentions using Twitter4j api


I want to get the count of tweets mentions a specific user. I try searching with query "@username" but I have only 15 results. Any idea?

*(Also I have not problem to use twitter Api)

    ConfigurationBuilder cb = new ConfigurationBuilder();

    cb.setOAuthConsumerKey("XXXXX");
    cb.setOAuthConsumerSecret("XXXXXX");
    cb.setOAuthAccessToken("XXXXX");
    cb.setOAuthAccessTokenSecret("XXXXX");

    // gets Twitter instance with default credentials
    Twitter twitter = new TwitterFactory(cb.build()).getInstance();

    Query query = new Query("@firefox");
    QueryResult search = twitter.search(query);
    System.out.println("count"+search.getCount());

Solution

  • Use twitter's streaming api and track the keywords or mentions.

    Example: https://github.com/yusuke/twitter4j/blob/master/twitter4j-examples/src/main/java/twitter4j/examples/stream/PrintFilterStream.java

    (Uses twitter4j).

    You can count the number of times a keyword is mentioned from the time you start runnung this program. You cannot count past tweets. You have rate limitations in searching past tweets.

    https://dev.twitter.com/docs/rate-limiting/1.1