如何使用YouTube API下载本人已举办的直播活动?
How to Download Your Own YouTube Live Stream via API
Hey there! I’ve run into this exact issue before—YouTube’s UI lets you download your own live replays easily, but tracking down the right API endpoints can feel like a needle-in-haystack job. Here’s a straightforward breakdown to get it working:
1. Lock in the Right API Access First
- You’ll need to use the YouTube Data API v3—this is the official tool for managing your own YouTube content.
- Authenticate with OAuth 2.0 credentials that have the right permissions:
- For read-only access to download your videos, use the scope
https://www.googleapis.com/auth/youtube.readonly - If you need broader control (like managing future broadcasts), go with
https://www.googleapis.com/auth/youtube
- For read-only access to download your videos, use the scope
- Don’t forget to enable the YouTube Data API v3 in your Google Cloud Console project and set up OAuth credentials for your app/script.
2. Grab the Video ID of Your Completed Live Stream
Once a live stream ends, it converts into a regular YouTube video. First, you need to pull the video ID linked to your finished broadcast:
- Use the
liveBroadcasts.listendpoint with these parameters:part=snippetbroadcastStatus=completedmine=true(this filters results to only your own broadcasts)
- In the response, you’ll find the associated video ID under
items[].snippet.resourceId.videoId
Alternatively, use the search.list endpoint for a more direct approach:
part=snippettype=videoeventType=completedmine=true
This will return all your completed live stream videos directly, no extra steps needed.
3. Download the Video Using the Media API
With the video ID in hand, you can pull the actual video file using Google’s media download tools:
- First, confirm ownership (though if you used
mine=trueearlier, this is already a given) with thevideos.listendpoint andpart=contentDetails. - Then, use Google’s client libraries (like
google-api-python-clientfor Python) to handle the download. Here’s a quick example snippet:from googleapiclient.discovery import build from googleapiclient.http import MediaIoBaseDownload import io # Initialize the API client with your OAuth credentials youtube = build('youtube', 'v3', credentials=your_oauth_credentials) # Start the download process request = youtube.videos().get(id=YOUR_LIVE_STREAM_VIDEO_ID) file_handle = io.FileIO('my_live_replay.mp4', 'wb') downloader = MediaIoBaseDownload(file_handle, request) done = False while not done: status, done = downloader.next_chunk() print(f"Download progress: {int(status.progress() * 100)}%")
Quick Important Notes
- You can only download videos you own—this API won’t let you access other users’ content.
- If you hit permission errors, double-check your OAuth scope and make sure you’re authenticated as the live stream’s owner.
- The download will default to the highest available quality, but you can specify quality parameters in the media downloader if needed.
内容的提问来源于stack exchange,提问作者Vladimir
相关产品推荐
相关产品推荐

