tweepy,twitter API将推特限制为一天
我正试图为一个项目从Twitter上收集一个月左右的数据。有这是答案。注意:您需要遍历tweepy,twitter API将推特限制为一天,twitter,tweepy,Twitter,Tweepy,我正试图为一个项目从Twitter上收集一个月左右的数据。有这是答案。注意:您需要遍历光标,如下所示。此外,还有一个可以传递的最大计数.items(),因此逐月拉取或类似的方法可能是一个好主意,在调用之间睡眠可能是一个好主意。嗯 igsjc_tweets_jan = [tweet for tweet in tweepy.Cursor( api.search, q="#igsjc", since='2016-01-01', until='2016-01-31
光标
,如下所示。此外,还有一个可以传递的最大计数.items()
,因此逐月拉取或类似的方法可能是一个好主意,在调用之间睡眠可能是一个好主意。嗯
igsjc_tweets_jan = [tweet for tweet in tweepy.Cursor(
api.search, q="#igsjc", since='2016-01-01', until='2016-01-31').items(1000)]
首先,tweepy不能使用其搜索API带来太旧的数据
我不知道确切的限制,但可能只有一两个月的时间
反正,
您可以使用这段代码获取推文。
我运行它是为了获得过去几天的tweet,它对我很有用
请注意,您可以对其进行优化并添加地理代码信息-我为您留下了一个注释过的示例
flag = True
last_id = None
while (flag):
flag = False
for status in tweepy.Cursor(api.search,
#q='geocode:"37.781157,-122.398720,1mi" since:'+since+' until:'+until+' include:retweets',
q="#igsjc",
since='2015-12-31',
max_id=last_id,
result_type='recent',
include_entities=True,
monitor_rate_limit=False,
wait_on_rate_limit=False).items(300):
tweet = status._json
print(Tweet)
flag = True # there still some more data to collect
last_id = status.id # for next time
祝你好运我刚读到搜索API只有大约一周前的推文。有什么办法可以解决这个问题吗?我想如果你阅读用户时间线,你可以得到一周以上的推文。是另一个类似的SO问题的链接。对你来说,最有帮助的答案是链接到“GetOldTweets”repo的答案。你在这方面成功了吗?它在“自”日期之前返回推特。@JasonVondersmith-我记得它按预期工作(1.5年前)。“自”?自=“2017-10-10”中传递的值是什么?我正在尝试在以下位置使用代码:
igsjc_tweets_jan = [tweet for tweet in tweepy.Cursor(
api.search, q="#igsjc", since='2016-01-01', until='2016-01-31').items(1000)]
flag = True
last_id = None
while (flag):
flag = False
for status in tweepy.Cursor(api.search,
#q='geocode:"37.781157,-122.398720,1mi" since:'+since+' until:'+until+' include:retweets',
q="#igsjc",
since='2015-12-31',
max_id=last_id,
result_type='recent',
include_entities=True,
monitor_rate_limit=False,
wait_on_rate_limit=False).items(300):
tweet = status._json
print(Tweet)
flag = True # there still some more data to collect
last_id = status.id # for next time