为什么我知道有喜欢的tweets使用tweepyapi对他们最喜欢的计数有0个回报?

2024-09-29 00:20:05 发布

您现在位置:Python中文网/ 问答频道 /正文

基本上,当我在Twitter上看到我知道“喜欢”的tweets,并打印出它们的favorite count属性时,计数总是0。favorite count与likes数量不一样/为什么favorite count总是0/我如何获得一条微博的赞数?在

现在我要做的是:

print(the_tweet.favorite_count)

打印时:

^{pr2}$

我看到很多与tweet有关的东西,包括retweet_count和favorite_count,但没有什么东西看起来像是“like_count”。在


Tags: the数量属性counttwitterfavoritetweetslike
1条回答
网友
1楼 · 发布于 2024-09-29 00:20:05

我只是用这个为我工作。我也遇到了同样的问题,因为我使用的是'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

相关问题 更多 >