如何获取视频推文的播放量?search/tweets接口无法获取该数据
Hey there! Great question—this is a common pain point since the standard search/tweets endpoint (whether v1.1 or v2) doesn't return video view counts directly in search results. But there are solid workarounds using Twitter's API v2, which is the current supported version:
1. 使用Tweet Lookup端点直接获取播放量
Twitter API v2's Tweet lookup endpoint (both single and batch) exposes video view counts via the public_metrics field. When you request tweet details with the right parameters, you'll get the view_count value specifically for video/animated content.
To use this:
- Make a GET request to
https://api.twitter.com/2/tweets(for batch lookup) orhttps://api.twitter.com/2/tweets/{tweet_id}(for single tweets) - Include the query parameter
tweet.fields=public_metrics - In the response, under each tweet's
public_metricsobject, you'll findview_count—this is exactly the video play count you're looking for.
Example request snippet (batch lookup):
GET /2/tweets?ids=1456789012345678901,1456789012345678902&tweet.fields=public_metrics
2. 结合搜索接口批量获取
If you need to first search for tweets (like you were doing with search/tweets) and then get their view counts, follow this workflow:
- Use the v2 search endpoints (
/2/tweets/search/recentfor recent tweets, or/2/tweets/search/allfor full archive access—requires academic research access) to fetch the IDs of tweets you care about. - Take that list of tweet IDs and pass them to the batch
Tweet lookupendpoint mentioned above to retrieve theview_countfor each video tweet.
Key Notes
- API Version: Avoid relying on v1.1 endpoints for this—most v1.1 endpoints don't support
view_countanymore, and Twitter is phasing out v1.1 in favor of v2. - Permissions: Ensure your API project has the correct access level. For example,
/2/tweets/search/allrequires academic research access, while/2/tweets/search/recentis available to most standard projects. - Field Availability: The
view_countfield only appears for tweets with video or animated GIF content. For regular text/image tweets, this field will benullor omitted.
内容的提问来源于stack exchange,提问作者MazarD

