簡體   English   中英

如何使用ruby twitter gem獲取大量推文

[英]How to get lots of tweets using ruby twitter gem

我寫了一些ruby來返回包含一個時間范圍內的短語的所有推文。 但是,此代碼最多可返回1,500條推文。 如何獲得超過1,500條推文? (我希望得到成千上萬的推文)

require "rubygems"
require "twitter"

    # returns a list of tweets containing the phrase within the dates specified
    # returns either @max_tweets tweets or all tweets found
    # @param phrase - a phrase to search for
    # @param from_date - begining date of the search ex."2011-02-28"
    # @param until_date - ending date of the search ex. "2011-03-01"
    def get_tweets(phrase, from_date, until_date)

      search = Twitter::Search.new.containing(phrase).since_date(from_date).until_date(until_date)

      #get all the tweets
      tweets = search.fetch
      next_tweets = search.fetch_next_page
      while(tweets.size < @max_tweets && next_tweets != nil) 
        tweets = tweets + next_tweets
        next_tweets = search.fetch_next_page
      end

      return tweets.first(@max_tweets)
    end

Twitter API文檔陳述

rpp
The number of tweets to return per page, up to a max of 100.
http://search.twitter.com/search.json?rpp=100

page
The page number (starting at 1) to return, up to a max of roughly 1500 results (based on rpp * page).
http://search.twitter.com/search.json?page=10

因此看起來1500是內置限制。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM