gpt4 book ai didi

ruby - 如何使用 ruby​​ twitter gem 获取大量推文

转载 作者:数据小太阳 更新时间:2023-10-29 07:33:01 26 4
gpt4 key购买 nike

我写了一些 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 docs状态

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 是一个内置限制。

关于ruby - 如何使用 ruby​​ twitter gem 获取大量推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5250511/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com