I would like to get the average engagement on twitter, which is: likes + retweets + comments over the last 30 tweets. I saw that you can get likes and retweets with tweepy:
tweepy_api = tweepy.API(auth)
user = tweepy_api.get_user('test_name')
# fetching the last 30 tweets
my_tweets = tweepy_api.user_timeline(screen_name=('test_name',
count=30,
include_rts=True,
tweet_mode='extended'
)
reactions = []
for el in my_tweets:
reactions.append(el.retweet_count)
reactions.append(el.favorite_count)
average = sum(reactions) / len(reactions)
However it doesn't get the retweets when I double checked and I do not know why.
I also found this to extract a tweet's replies:
name = 'LunarCRUSH'
tweet_id = '1270923526690664448'
replies=[]
for tweet in tweepy.Cursor(api.search,q='to:'+name, result_type='recent', timeout=999999).items(1000):
if hasattr(tweet, 'in_reply_to_status_id_str'):
if (tweet.in_reply_to_status_id_str==tweet_id):
replies.append(tweet)
And I guess I would just have to add the length of the replies to my favorites and retweets to get engagement but once again, it doesn't work and I do not know what to do. Any help would be really appreciated. Thanks,