我正在将 Tweepy 与 python 结合使用,并尝试获取由一组用户创作的原始推文(即,我想排除其时间线中实际上是转发的任何推文)。我怎样才能用 Tweepy 做到这一点?
我尝试过类似的方法,但我不知道它是否有效:
tweets = api.user_timeline(id=user['id'], count=30)
for tweet in tweets:
if not tweet.retweeted:
analyze_tweet(tweet)
是否api.user_timeline()
只返回原始推文?或者也转发该用户?
默认情况下,Tweepy 不包含 user_timeline 中的转发,因此 tweet.retweeted 将始终为 false。要包含转发,您可以将 include_rts 指定为 True ,例如
tweets= api.user_timeline(id=user['id'], count=30,include_rts=True)
for tweet in tweets:
if not tweet.retweeted:
analyze_tweet(tweet)
else:
#do something with retweet
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)