Estoy tratando de obtener todos los tweets en Twitter a través del objeto twitter4j TwitterStream. No estoy seguro de estar recibiendo todos los tweets. Para el ensayo de la demora después de lo cual la API de streaming devuelve el pío, he publicado un tweet de mi cuenta en twitter. Pero no recibí ese tweet incluso después de mucho tiempo.Twitter4j TwitterStream no recibe todos los tweets
¿Captura el twitter4j todos y cada uno de los tweets publicados en Twitter o pierde un buen porcentaje de los tweets? ¿O estoy haciendo algo mal aquí? Aquí está el código que estoy usando para obtener los 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();