Twitter4j的TwitterStream无法获取所有推文

5
我正在尝试通过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();
1个回答

10

我很乐意接受这方面的质疑,但我认为它是这样工作的...

对于非合作伙伴,流媒体API只提供推文的样本。 这是“花园水管”,而少数Twitter合作伙伴可以获得“消防栓”。 但您可以申请完全访问权限。

.sample()提供了这个“花园水管”。 尽管我认为如果您有访问权限,则会有一个twitterStream可以访问“消防栓”。

在此页面上搜索“statuses / sample”以获取详细信息:https://dev.twitter.com/docs/streaming-api/methods


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接