2011-09-25 5 views
5

私はtwitter4jのTwitterStreamオブジェクトを通じて、すべてのつぶやきをtwitterで取得しようとしています。私はすべてのつぶやきを取得しているかどうかはわかりません。ストリーミングAPIがツイートを返す遅延をテストするために、私は自分のアカウントからツイートでツイートを投稿しました。しかし、私は長い間このツイートを受けていませんでした。Twitter4j TwitterStreamがすべてのつぶやきを取得しない

twitter4jがツイートに投稿されたツイートをすべて捕まえているのですか、それともツイートの割合が良いのでしょうか?あるいは私はここで何か間違っているのですか?

ストリーミングAPIのみのサンプルを提供します...私はこの上で矛盾して開いている

 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(); 

答えて

10

、私はそれがこのように動作します信じる: は、ここで私はつぶやきを取得するために使用していたコードです非パートナーのつぶやきそれは、いくつかのTwitterパートナーが手に入れる「firehose」とは対照的に、「庭のホース」です。しかし、あなたは完全なアクセスを申請することができます。

。サンプル()はこの "庭用ホース"を示しています。あなたのTwitterアカウントにはFirehoseへのアクセス権がありませんが、もし私がFirehoseにアクセスしていればtwitterStreamがあると思います。

詳細については、このページの「ステータス/サンプル」を検索してください。https://dev.twitter.com/docs/streaming-api/methods

関連する問題