问题
I'm trying to get twitters timelime using tweepy, but I can't get old tweets that are more than a year ago.
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'
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.
回答1:
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.
If you need historic data, then Twitter's Gnip products offer comprehensive coverage. These are commercial APIs.
来源:https://stackoverflow.com/questions/40756263/how-can-i-get-tweets-more-than-a-year