How can I get tweets more than a year

送分小仙女□ 提交于 2019-12-12 04:28:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!