如何 reply_count & quote_count 使用 tweepy 3.10.0?

How to reply_count & quote_count using tweepy 3.10.0?

我正在尝试使用 Twitter Tweepy API 执行 quote_count & reply_count,但我找不到关于如何执行此操作的正确更新文档。

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

我有一些来自 Tweepy for Twitter API 版本 1 的工作代码来获取我使用的一些数据,但是我找不到关于如何提取 reply_countquote_count 的有用信息Twitter API 版本 2 通过 Tweepy。

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()

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

如该文档所述,您需要在发出 API 请求时传递所需的特定字段和扩展。 例如,对于当前在 master 分支上的版本,该文档中 public 指标示例请求的等效项是:

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

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

>>> 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}