在tweepy中查询user_timeline时忽略count参数

时间:2017-01-20 14:20:16

标签: python python-3.x tweepy

我正在尝试在我的一个python项目中使用tweepy库。当我尝试以下代码创建一个tweepy游标来获取用户的时间轴状态消息时,count参数始终被忽略。

def search(self, username, keyword, consumer_key, consumer_secret, access_token, access_token_secret):
    #start twitter auth
    try:
        auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
        api = tweepy.API(auth)
        user = api.get_user(username)
    except Exception as e:
        print(str(e))
        self.error = str(e)
        return
    self.followercount = user.followers_count
    self.screenname = user.screen_name
    results = []
    for status in tweepy.Cursor(api.user_timeline, id=username, count=2).items():
        try:
            tweet = status._json

在这种情况下,Cursor对象中的count设置为2,但它接收所有这些。我做错了什么?

1 个答案:

答案 0 :(得分:2)

tweepy.Cursor()似乎无法识别count参数。事实上,tweepy/cursor.py中没有提到counttweepy.Cursor是定义for status in tweepy.Cursor(api.user_timeline, id=username).items(2): 的模块。相反,看起来您可能想要使用:

items()

将限制传递给count而不是Item关键字参数。请参阅tweepy this section中的Cursor tutorial