Python 使用Tweepy打印来自朋友的推文

Python 使用Tweepy打印来自朋友的推文,python,twitter,tweepy,Python,Twitter,Tweepy,在过去的3个小时里,我一直在想Tweepy,但我还是被卡住了。 我希望能够在2014年9月至10月期间获得我朋友的所有推文,并通过前10个转发次数进行过滤 我只对StreamListener略为熟悉,但我认为这是一个实时推文列表。我想知道我是否能回到上个月,从我的朋友那里得到那些推特。这可以通过Tweepy完成吗?这就是我现在的代码 from tweepy import Stream from tweepy import OAuthHandler from tweepy.streaming im

在过去的3个小时里,我一直在想Tweepy,但我还是被卡住了。 我希望能够在2014年9月至10月期间获得我朋友的所有推文,并通过前10个转发次数进行过滤

我只对StreamListener略为熟悉,但我认为这是一个实时推文列表。我想知道我是否能回到上个月,从我的朋友那里得到那些推特。这可以通过Tweepy完成吗?这就是我现在的代码

from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener

import csv

ckey = 'xyz'
csecret = 'xyz'
atoken = 'xyz'
asecret = 'xyz'

auth = OAuthHandler(ckey,csecret)
auth.set_access_token(atoken, a secret)

class Listener(StreamListener):
    def on_data(self,data):
        print data
        return True
    def on_error(self,status):
        print status

auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
tiwtterStream = Stream(aut, Listener())

users = [123456, 7890019, 9919038] # this is the list of friends I would like to output
twitterStream.filter(users, since=09-01-2014, until = 10-01-2014)

您认为
StreamListener
返回实时推文是正确的。要获得特定用户的推文,您需要使用tweepy的API包装--
tweepy.API
。下面是一个示例,它将从您的
侦听器
类中替换:

api = tweepy.API(auth)
tweetlist = api.user_timeline(id=123456)
这将返回最多20个
status
对象的列表。为了得到更多的结果,您可能需要处理
count
,因为
将有助于您的实现。我想你最多只能要求一次
count

注意:这不是一个大问题,但您在代码中进行了两次身份验证,这是不必要的