Twitter4j TwitterStream doesn't get all the tweets

I am trying to get all the tweets on twitter via the twitter4j TwitterStream object. I'm not sure I get all the tweets. To test the delay after which the streaming API returns a tweet, I sent a tweet from my twitter account. But I did not get this tweet even after a long time.

Does twitter4j catch every twitter post on Twitter, or does it lose a good percentage of tweets? Or am I doing something wrong? Here is the code I use to get tweets:

        StatusListener listener = new StatusListener(){
        int countTweets = 0;    // Count to implement batch processing

        public void onStatus(Status status) {
            countTweets ++;
            StatusDto statusDto = new StatusDto(status);
            session.saveOrUpdate(statusDto);

            // Save 1 round of tweets to the database
            if (countTweets == BATCH_SIZE) {
                countTweets = 0;
                session.flush();
                session.clear();
            }
        }

        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {}

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {}

        public void onException(Exception ex) {
            ex.printStackTrace();
        }

        public void onScrubGeo(long arg0, long arg1) {
            // TODO Auto-generated method stub
        }           
    };

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
      .setOAuthConsumerKey(Twitter4jProperties.CONSUMER_KEY)
      .setOAuthConsumerSecret(Twitter4jProperties.CONSUMER_SECRET)
      .setOAuthAccessToken(Twitter4jProperties.ACCESS_TOKEN)
      .setOAuthAccessTokenSecret(Twitter4jProperties.ACCESS_TOKEN_SECRET);

    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    twitterStream.addListener(listener);

    session = HibernateUtil.getSessionFactory().getCurrentSession();
    transaction = session.beginTransaction();

    // sample() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
    twitterStream.sample();
+5
source share
1 answer

I am open to controversy about this, but I believe that it works like this ...

Streaming API -. " ", "firehose", Twitter. .

.sample() " ". Twitter firehose, , firehose, .

"/" : https://dev.twitter.com/docs/streaming-api/methods

+10

All Articles