繁体   English   中英

Twitter4j TwitterStream没有收到所有推文

[英]Twitter4j TwitterStream doesn't get all tweets

我试图通过twitter4j TwitterStream对象获取Twitter上的所有推文。 我不确定我收到了所有的推文。 为了测试流API返回推文之后的延迟,我在twitter上发布了一条推文。 但即使很长一段时间后我也没有收到这条推文。

twitter4j是否会抓住Twitter上发布的每条推文,或者它的推文丢失率很高? 或者我在这里做错了什么? 这是我用来获取推文的代码:

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

我对此持开放态度,但我认为它的作用是这样的...

Streaming API仅提供非合作伙伴的推文样本。 它是“花园软管”,而不是一些Twitter合作伙伴得到的“firehose”。 但您可以申请完全访问权限。

.sample()给出了这个“花园软管”。 您的Twitter帐户将无法访问firehose,但我认为如果您确实有访问权限,则会有一个用于firehose的twitterStream。

在此页面上搜索“状态/样本”以获取具体信息: https//dev.twitter.com/docs/streaming-api/methods

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM