Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用ruby twitter gem获得大量推文_Ruby_Twitter - Fatal编程技术网

如何使用ruby twitter gem获得大量推文

如何使用ruby twitter gem获得大量推文,ruby,twitter,Ruby,Twitter,我写了一些ruby来返回在一定时间范围内包含短语的所有推文。但是,此代码最多返回1500条tweet。我怎样才能获得超过1500条推文?(我希望收到数十万条推特) 需要“rubygems” 需要“推特” #返回在指定日期内包含短语的tweet列表 #返回@max_tweets tweets或找到的所有tweets #@param短语-要搜索的短语 #@param from_date-搜索开始日期,例如“2011-02-28” #@param until_date-搜索结束日期,例如“2011-0

我写了一些ruby来返回在一定时间范围内包含短语的所有推文。但是,此代码最多返回1500条tweet。我怎样才能获得超过1500条推文?(我希望收到数十万条推特)

需要“rubygems”
需要“推特”
#返回在指定日期内包含短语的tweet列表
#返回@max_tweets tweets或找到的所有tweets
#@param短语-要搜索的短语
#@param from_date-搜索开始日期,例如“2011-02-28”
#@param until_date-搜索结束日期,例如“2011-03-01”
def get_推文(短语,从_日期到_日期)
search=Twitter::search.new.containing(词组).自\u日期(自\u日期).至\u日期(至\u日期)
#获取所有推文
tweets=search.fetch
next_tweets=search.fetch_next_页面
while(tweets.size<@max_tweets&&next_tweets!=nil)
推文=推文+下一条推文
next_tweets=search.fetch_next_页面
结束
返回tweets.first(@max_tweets)
结束
状态


因此,1500似乎是一个内置的限制。

好吧,如果ruby twitter gem不起作用,你还有什么其他想法来获取大量推文吗?推特有一个流式API,可以让你实时收集和过滤推文;我敢肯定,“收获”推特的公司就是这样得到它们的。
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
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