基本上,当我在Twitter上看到我知道已经被“赞”的tweet,并打印出它们最喜欢的count属性时,count总是0。收藏数不等于点赞数/为什么收藏数总是0/如何获取推文的点赞数?
现在,我正在做以下工作:
print(the_tweet.favorite_count)当我打印时:
print(dir(the_tweet)) 我看到了很多与tweet有关的东西,包括retweet_count和favorite_count,但没有一个看起来像"like_count“。
发布于 2018-06-04 01:16:50
我只是用了这个,为我自己工作。我也遇到了同样的问题,这是因为我使用了'tweepy‘,它在json api中为favorite_count返回两个值,一个是正确的值,另一个是'0’。当你使用'Twython‘时,它只返回一个值,第一个值。
pip install twython
from twython import Twython
id_of_tweet = <tweet_number_id>
CONSUMER_KEY = "<consumer key>"
CONSUMER_SECRET = "<consumer secret>"
OAUTH_TOKEN = "<application key>"
OAUTH_TOKEN_SECRET = "<application secret>"
twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN,
OAUTH_TOKEN_SECRET)
tweet = twitter.show_status(id=id_of_tweet)
print(tweet)
print(tweet['retweet_count'])
print(tweet['favorite_count'])这个解决方案的一部分就在这个闲置中:Twitter API - get tweets with specific id
发布于 2020-02-20 00:16:27
我也遇到过同样的问题,favorite_count显示了你自己的推文,而the_tweet对象是你的user_timeline对象,它是推文和转发的混合体。因此,您需要检查retweeted_status是否存在,如果存在,则转发的tweet的favorite_count就在此列表下。请看我下面的例子:
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)此外,如果您使用的是Django模板标记,则可以使用以下内容:
{% if tweet.retweeted_status %}
<small>{{ tweet.retweeted_status.favorite_count }}</small>
{% else %}
<small>{{ tweet.favorite_count }}</small>
{% endif %}发布于 2021-07-14 14:43:45
我也遇到过类似的问题。对我来说,问题是这条推文是一条转发,处理方法如下。包括一个新的tweet值referenced_tweets和public_metrics,它将以ID的形式返回任何引用的tweet.fields。然后在新的呼叫(相同的路由)中使用此ID和public_metrics,以获取转发推文的真实指标。
https://stackoverflow.com/questions/46536550
复制相似问题