问题描述
我正在尝试使用 tweepy 获取 twitter 的时间段,但我无法获取超过一年前的旧推文.
I'm trying to get twitters timelime using tweepy, but I can't get old tweets that are more than a year ago.
我的 Python 脚本如下所示:
My Python script is shown below:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import unicode_literals
import tweepy
import json
CONSUMER_KEY = 'XXXXXXXXXXXXXXXXXXXXX'
CONSUMER_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
ACCESS_TOKEN = 'XXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
ACCESS_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)
user = api.get_user(screen_name='twitter_acount')
for tw in tweepy.Cursor(api.user_timeline, user_id=user.id, count=15000).items():
json_str = json.dumps(tw._json)
print json_str
print '\n'
我执行此脚本是为了获取推文超过 15000 条的用户的推文,但我只收到了大约 3113 条推文,而且我收到的最早推文的日期是 2015 年 11 月 22 日,即一年前.
I executed this script for getting tweets of a user who tweeted more than 15000, but I only got about 3113 tweets and the date of the oldest tweet I got is 22 Nov 2015, i.e., a year ago.
推荐答案
Twitter 搜索 API 限制为 7 天的历史记录,时间线 API 限制可检索的推文数量.实际上你应该只能获取 3200 条推文 所以我不知道你对 9800 的看法如何.
The Twitter Search API is limited to 7 days of history, and the timeline APIs are limited on the number of Tweets that can be retrieved. Actually you should only be able to fetch 3200 Tweets so I'm not sure how you're seeing 9800.
如果您需要历史数据,Twitter 的 Gnip 产品 提供全面的覆盖.这些是商业 API.
If you need historic data, then Twitter's Gnip products offer comprehensive coverage. These are commercial APIs.
这篇关于我怎样才能得到超过一年的推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!