I had the same issue, favorite_count
shows the likes of your own tweet, while the_tweet
object is your user_timeline object which is a mixture of tweets and retweets. Therefore you need to check to see if retweeted_status
exist and if so favorite_count
for the retweeted tweets are under this list. Please check my example below:
def user_tweets(count):
'''
This function uses tweepy to read the user's twitter feed.
'''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# user = api.get_user(twitter_user_name)
user_tweets = api.user_timeline(twitter_user_name, count=count)
return user_tweets
user_tweets(4)# returns your latest 4 tweets and retweets
#to list the number of likes for each tweet and retweet:
for tweet in user_tweets:
try:
print(tweet.retweeted_status.favorite_count)
except:
print(tweet.favorite_count)
Also if you are using Django template tags you can use the following:
{% if tweet.retweeted_status %}
<small>{{ tweet.retweeted_status.favorite_count }}</small>
{% else %}
<small>{{ tweet.favorite_count }}</small>
{% endif %}