The*_*Dan 3 python twitter tweepy
我正在尝试执行quote_count并reply_count使用 Twitter Tweepy API,但我找不到有关如何执行此操作的正确更新文档。
https://developer.twitter.com/en/docs/twitter-api/metrics
我有一些来自 Tweepy 的 Twitter API 版本 1 的工作代码来获取我使用的一些数据,但我找不到有关如何通过 Tweepy 提取reply_count和quote_count使用 Twitter API 版本 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()
Run Code Online (Sandbox Code Playgroud)
Tweepy v3.10.0 不支持 Twitter API v2。\n您必须在 master 分支上使用 Tweepy 的最新开发版本或等待 Tweepy v4.0 发布。
\n正如该文档所述,您需要在发出 API 请求时传递所需的特定字段和扩展。\n例如,对于当前位于 master 分支上的版本,该文档中的公共指标示例请求的等效项将是:
\nresponse = client.get_tweets(\n ids=[1204084171334832128],\n tweet_fields=["public_metrics"],\n expansions=["attachments.media_keys"],\n media_fields=["public_metrics"]\n)\nRun Code Online (Sandbox Code Playgroud)\n然后,您可以通过Tweet和Media对象的属性来访问它们:
\n>>> response\nResponse(data=[<Tweet id=1204084171334832128 text=Tired of reading? We\xe2\x80\x99ve got you covered. Learn about the capabilities of the Account Activity API in this video walkthrough with @tonyv00 from our DevRel team. \xe2\xac\x87\xef\xb8\x8f [. . .] >], includes={\'media\': [<Media media_key=13_1204080851740315648 type=video>]}, errors=[], meta={})\n>>> response.data[0].public_metrics\n{\'retweet_count\': 9, \'reply_count\': 2, \'like_count\': 52, \'quote_count\': 2}\n>>> response.includes["media"][0].public_metrics\n{\'view_count\': 1946}\nRun Code Online (Sandbox Code Playgroud)\n