Periodically fetching data From twitter4j Steaming API


I want to fetch periodic data from twitter using twitter4j streaming API.
eg: i want 03/03/2014 to 04/05/2014 tweets data. I tried but didn't get the expected result. Also searched google for some solutions but didn't get an approach to solving this issue.

I am trying to use the following code:

public class Twitter_Data {

    public static void main(String[] args) {

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true);
        cb.setOAuthConsumerKey("myKey");
        cb.setOAuthConsumerSecret("mySecretCode");
        cb.setOAuthAccessToken("Token");
        cb.setOAuthAccessTokenSecret("secret token");
        TwitterStream twitterStream = new TwitterStreamFactory(cb.build())
                .getInstance();

        StatusListener listener = new StatusListener() {
            @Override
            public void onStatus(Status status) {
                User user = status.getUser();

                // gets Username info
                long userId = user.getId();
                String userNm = user.getName();
                System.out.println("User ID: " + userId);
                System.out.println("User Name: " + userNm);

                String profileLocation = user.getLocation();
                System.out.println(profileLocation);

                long tweetId = status.getId();
                System.out.println(tweetId);
                String content = status.getText();
                System.out.println(status.toString() + "\n");
            }

        };
        FilterQuery fq = new FilterQuery();
        String keywords[] = { "Key word" };
        fq.track(keywords);
        twitterStream.addListener(listener);
        twitterStream.filter(fq);

    }

}

      

Can anyone help me, extract periodic data using this code. Thanks in Advance.

+3


source to share


1 answer


I want to fetch periodic data from twitter using twitter4j streaming API.



You can't do that, the Streaming API is for tweets at the time you use it. In your example, you will get Tweets about your keyword that people are tweeting about right now. With the Twitter API, you cannot receive tweets for a certain period of time.

+2


source







All Articles