首页 > 解决方案 > Tweepy 将搜索限制为单个用户

问题描述

我正在尝试使用 tweepy api 搜索用户自己的推文,并返回包含用户输入的任何关键字的推文。因此,如果用户输入“Blue”作为关键字,它将搜索所有用户的推文,并返回任何包含字符串“Blue”的推文。

到目前为止,这是我的代码,它可以运行,但它似乎可以无限运行各种随机推文。如何将搜索限制为单个用户?

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)

api = tweepy.API(auth)

for status in tweepy.Cursor(api.search, q="Blue", rpp=100, show_user=True).items():
    print status.text

标签: pythontwittertweepy

解决方案


from:user在查询中使用添加用户的 twitter 句柄:

for status in tweepy.Cursor(api.search, q="Blue from:blueperson", rpp=100, show_user=True).items():
    print status.text

推荐阅读