如何使用 tweepy 3.10.0 回复计数和引用计数?

3

我正在使用Twitter Tweepy API尝试执行quote_countreply_count,但是我找不到关于如何执行这些操作的适当更新文档。

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

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

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()
1个回答

5

Tweepy v3.10.0不支持Twitter API v2。您需要使用主干分支上的最新开发版本或等待Tweepy v4.0发布。

正如该文档所述,您需要在进行API请求时传递您想要的特定字段和扩展。例如,在当前主干分支上,公共指标示例请求的等效内容将是:

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

接下来,您可以通过推文媒体对象的属性来访问它们:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接