twittertwitter4j

Twitter: Get tweets for a particular time period


I am new to Twitter APIs. I am implementing a module in Java which shows popularity of a #hashtag. So I have to collect tweets for regular time interval.

Is there a way to get all the tweets that contains particular #hashtag, so I can the count total tweets each time and get the popularity? Below URL give me tweets but it's not consistent. Doesn't give me all tweets.

http://search.twitter.com/search.json?q=%23example


Solution

  • Why are you using urls use Api Twitter 4j

    http://twitter4j.org/en/

    You can perform this function eaisly with that

    With Twitter4J, you can easily integrate your Java application with the Twitter service.

    But Twitter4J is an unofficial library.

    Use this function of that api

    Search for Tweets

     // The factory instance is re-useable and thread safe.
        Twitter twitter = TwitterFactory.getSingleton();
        Query query = new Query("source:twitter4j yusukey");
        QueryResult result = twitter.search(query);
        for (Status status : result.getStatuses()) {
            System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
        }
    

    Check this url for snippets

    http://twitter4j.org/en/code-examples.html