【问题标题】:Tweepy restricting a search to a single userTweepy 将搜索限制为单个用户
【发布时间】:2018-11-30 07:25:35
【问题描述】:

我正在尝试使用 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

【问题讨论】:

    标签: python twitter tweepy


    【解决方案1】:

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

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

    【讨论】:

    • 我可以在里面使用多个用户名吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 1970-01-01
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 2015-10-20
    • 1970-01-01
    相关资源
    最近更新 更多