【问题标题】:Get ALL tweets, not just recent ones via twitter API (Using twitter4j - Java)通过 twitter API 获取所有推文,而不仅仅是最近的推文(使用 twitter4j - Java)
【发布时间】:2013-12-25 08:12:58
【问题描述】:

我使用 twitter4j 构建了一个应用程序,当我输入关键字时,它会拉入一堆推文,从推文中提取地理位置(或回退到配置文件位置),然后使用 ammaps 映射它们。问题是我只收到一小部分推文,这里有什么限制吗?我有一个数据库很快就会收集推文数据,它会有相当多的数据,但我很好奇为什么我只在过去 12 小时左右收到推文?

例如,如果我按我的用户名搜索,我只会收到一条我今天发送的推文。

感谢您提供任何信息!

编辑:我知道 twitter 不允许公众访问 firehose.. 为什么我仅限于查找最近的推文?

【问题讨论】:

    标签: api twitter twitter4j


    【解决方案1】:

    您需要不断重做查询,每次都重新设置 maxId,直到您一无所获。您还可以使用 setSince 和 setUntil。

    一个例子:

    Query query = new Query();
    query.setCount(DEFAULT_QUERY_COUNT);
    query.setLang("en");
    // set the bounding dates 
    query.setSince(sdf.format(startDate));
    query.setUntil(sdf.format(endDate));
    
    QueryResult result = searchWithRetry(twitter, query); // searchWithRetry is my function that deals with rate limits
    
    while (result.getTweets().size() != 0) {
    
        List<Status> tweets = result.getTweets();
        System.out.print("# Tweets:\t" + tweets.size());
        Long minId = Long.MAX_VALUE;
    
        for (Status tweet : tweets) {
        // do stuff here            
            if (tweet.getId() < minId)
            minId = tweet.getId();
        }
        query.setMaxId(minId-1);
        result = searchWithRetry(twitter, query);
    

    }

    【讨论】:

    • 可以分享代码吗? :) 我也有同样的问题
    • @ThusithaThilinaDayaratne 您在寻找什么代码? Twitter4j API 有据可查。
    【解决方案2】:
    Really it depend on which API system you are using. I mean Streaming or Search API. In the search API there is a parameter (result_type) that is an optional parameter. The values of this parameter might be followings:
    
      * mixed: Include both popular and real time results in the response.
      * recent: return only the most recent results in the response
      * popular: return only the most popular results in the response.
    
    The default one is the mixed one.
    
    As far as I understand, you are using the recent one, that is why; you are getting the recent set of tweets. Another issue is getting low volume of tweets that have the geological information. Because there are very few users added the geological information to their profile, you are getting very few tweets.
    

    【讨论】:

    • 嘿,非常感谢您的回复。好的,这是有道理的。我正在剥离位置,所以我知道我会得到更少,但即使在我的代码达到 if (tweet.getGeoLocation != null) 的点之前,我仍然只得到一个包含 15 条推文的列表。你知道是否有什么办法可以提高这个限制,还是 twitter 设置的限制.. 非消防站有点限制?
    猜你喜欢
    • 2015-02-21
    • 1970-01-01
    • 2013-06-03
    • 2015-01-01
    • 2014-02-13
    • 2015-02-05
    • 1970-01-01
    • 2018-07-14
    • 2014-12-19
    相关资源
    最近更新 更多