如何检测YouTube指定文件是否为直播流?
Yes, this is totally feasible!
You can absolutely check if a specified YouTube video/stream is live (or an upcoming/completed live broadcast) using the YouTube Data API v3. I’ve worked through this exact use case before, so let me break down how to pull it off step by step:
1. Use the Videos.list endpoint
This is the core API endpoint you’ll need. You just need to pass two critical parameters:
id: The unique ID of the YouTube content you want to checkpart: SpecifysnippetandliveStreamingDetails— these are the sections that hold all the live status data
Here’s a quick example request using curl:
curl "https://www.googleapis.com/youtube/v3/videos?id=YOUR_TARGET_CONTENT_ID&part=snippet,liveStreamingDetails&key=YOUR_YOUTUBE_API_KEY"
2. Interpret the response
Look for these key fields in the API’s returned data to determine the content’s live status:
- Currently live stream:
snippet.liveBroadcastContentwill be set to"live"liveStreamingDetailswill include anactualStartTimetimestamp, and noactualEndTime(since the stream is still running)
- Upcoming scheduled live stream:
snippet.liveBroadcastContentwill be"upcoming"liveStreamingDetailswill have ascheduledStartTimetimestamp marking when the stream goes live
- Completed live stream (replay):
snippet.liveBroadcastContentwill be"completed"liveStreamingDetailswill contain bothactualStartTimeandactualEndTimetimestamps
- Regular non-live video:
- The
liveStreamingDetailsfield won’t appear in the response at all snippet.liveBroadcastContentwill be"none"
- The
Quick notes
- For public content, you only need a standard YouTube Data API key (no OAuth authentication required). If you’re checking private/unlisted live streams, you’ll need to authenticate with appropriate permissions.
- Double-check that your API key has the YouTube Data API v3 enabled in the Google Cloud Console before making requests.
内容的提问来源于stack exchange,提问作者Wojciech Urbaniak
相关产品推荐
相关产品推荐

