问题描述
我正在尝试运行 Tweepy StreamListener
以关注用户在 Twitter 上的推文。
当我使用 track
关键字时它有效,但当我添加 follow='userid'
时它挂起。我做错了什么吗?
stream_listener = StreamListener()
auth = OAuthHandler("","")
auth.set_access_token("","")
stream = Stream(auth=auth,listener=stream_listener)
#stream.filter(follow="")
api = tweepy.API(auth)
screen_name = "ThetaWarrior"
user = api.get_user(screen_name)
api = tweepy.API(auth,wait_on_rate_limit=True)
print("User details:")
print(user.name)
print(user.description)
print(user.location)
print(user.id_str)
stream.filter(follow="98**************")
解决方法
follow
参数需要是用户 ID 列表,而不是字符串,例如:stream.filter(follow=["98**************"])
假设 "98**************"
是实际用户 ID。
请参阅 the Streaming with Tweepy section of the documentation 以获取 Tweepy v3.10 或 the documentation for Stream.filter
以获取主分支上 Tweepy 的最新开发版本,即将发布为 v4.0。另见the documentation for the POST statuses/filter endpoint。