Twitter4j TwitterStream并未获取所有推文 [英] Twitter4j TwitterStream doesn't get all tweets

查看:114
本文介绍了Twitter4j TwitterStream并未获取所有推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过twitter4j TwitterStream对象获取Twitter上的所有推文.我不确定是否会收到所有推文.为了测试流式API返回推文之后的延迟,我从我的帐户在Twitter上发布了一条推文.但是即使很长一段时间我也没有收到那条推文.

I am trying to get all the tweets on twitter through the twitter4j TwitterStream object. I'm not sure that I am getting all the tweets. For testing the delay after which the streaming API returns the tweet, I posted a tweet from my account on twitter. But I didn't receive that tweet even after a long time.

twitter4j是否会捕获Twitter上发布的每条推文,还是会丢失大量的推文?还是我在这里做错了什么?这是我用来获取推文的代码:

Does the twitter4j catch each and every tweet posted on twitter or it loses a good percentage of the tweets? Or am I doing something wrong here? Here's the code that I am using to get the 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();

推荐答案

对此我很矛盾,但是我相信它的工作原理是这样的...

I'm open to contradiction on this, but I believe it works like this...

Streaming API仅提供非合作伙伴的推文样本.这是花园软管",而不是一些Twitter合作伙伴得到的消防水带".但是您可以申请完全访问权限.

Streaming API only gives a sample of tweets for non-partners. It's the "garden hose" as opposed to the "firehose" which a few Twitter partners get. But you can apply for full access.

.sample()提供此花园软管".您的twitter帐户将无法访问firehose,尽管我认为如果您有权访问firehose,则存在twitterStream.

.sample() gives this "garden hose". Your twitter account won't have access to the firehose, although I think there is a twitterStream for the firehose if you did have access.

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

Search for "statuses/sample" on this page for the specifics: https://dev.twitter.com/docs/streaming-api/methods

这篇关于Twitter4j TwitterStream并未获取所有推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆