2011-09-25 17 views
5

Sto cercando di ottenere tutti i tweet su Twitter tramite l'oggetto TwitterStream Twitter4j. Non sono sicuro di ricevere tutti i tweet. Per testare il ritardo dopo il quale l'API di streaming restituisce il tweet, ho postato un tweet dal mio account su Twitter. Ma non ho ricevuto quel tweet nemmeno dopo tanto tempo.Twitter4j TwitterStream non riceve tutti i tweet

Il twitter4j cattura ogni singolo tweet postato su twitter o perde una buona percentuale dei tweet? O sto facendo qualcosa di sbagliato qui? Ecco il codice che sto usando per ottenere i 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(); 

risposta

10

Sono aperto alla contraddizione su questo, ma credo che funziona così ...

Streaming API dà solo un esempio di tweets per i non partner. È il "tubo da giardino" in contrasto con il "firehose" ottenuto da alcuni partner di Twitter. Ma puoi richiedere l'accesso completo.

. Campione() fornisce questo "tubo da giardino". Il tuo account Twitter non avrà accesso a Firehose, anche se penso che ci sia un twitterStream per l'firehose se tu avessi accesso.

Cerca "stati/campione" in questa pagina per le specifiche: https://dev.twitter.com/docs/streaming-api/methods

Problemi correlati