如何使用tweepy 3.10.0回复\u count和引用\u count?

2024-06-30 11:13:40 发布

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

我正在尝试执行quote_count&reply_count使用twittertweepyapi,但我找不到关于如何使用它的适当更新文档

https://developer.twitter.com/en/docs/twitter-api/metrics

我从Tweepy获得了一些Tweepy的工作代码,用于获取我使用的一些数据,但是我找不到关于如何提取reply_count&quote_count通过Tweepy使用twitterapi版本2

import tweepy

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, proxy=proxy)

public_tweets = api.user_timeline()

Tags: 文档tokenauthapisecretaccessconsumercount
1条回答
网友
1楼 · 发布于 2024-06-30 11:13:40

Tweepy v3.10.0不支持Twitter API v2。 您必须在主分支上使用最新的Tweepy开发版本,或者等待Tweepy v4.0发布

正如该文档所述,在发出API请求时,需要传递所需的特定字段和扩展。 例如,对于主分支上当前的版本,该文档中的公共度量示例请求的等效值为:

response = client.get_tweets(
    ids=[1204084171334832128],
    tweet_fields=["public_metrics"],
    expansions=["attachments.media_keys"],
    media_fields=["public_metrics"]
)

然后,您可以通过TweetMedia对象的属性访问它们:

>>> response
Response(data=[<Tweet id=1204084171334832128 text=Tired of reading? We’ve got you covered. Learn about the capabilities of the Account Activity API in this video walkthrough with @tonyv00 from our DevRel team. 🍿 ⬇️ [. . .] >], includes={'media': [<Media media_key=13_1204080851740315648 type=video>]}, errors=[], meta={})
>>> response.data[0].public_metrics
{'retweet_count': 9, 'reply_count': 2, 'like_count': 52, 'quote_count': 2}
>>> response.includes["media"][0].public_metrics
{'view_count': 1946}

相关问题 更多 >