Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
- Description
I have an video that I want to uploaded captions to through the YouTube API. I built a python script that looks like the following:
def upload_caption(
video_id: str, file_path: str, language: str = "en", name: str = "English Caption"
):
credentials = os.getenv("YOUTUBE_OAUTH_CREDENTIALS")
if credentials is None:
raise ValueError("YOUTUBE_OAUTH_CLIENT_SECRET is required")
# Build the YouTube service
youtube = get_authenticated_service(credentials)
request = youtube.captions().insert(
part="snippet",
body={
"snippet": {
"language": language,
"name": name,
"videoId": video_id,
"isDraft": True,
}
},
media_body=MediaFileUpload(file_path),
)
response = request.execute()
It is for this video
- API request with parameters used (DO NOT include your credential)
# Build the YouTube service
youtube = get_authenticated_service(credentials)
request = youtube.captions().insert(
part="snippet",
body={
"snippet": {
"language": language,
"name": name,
"videoId": video_id,
"isDraft": True,
}
},
media_body=MediaFileUpload(file_path),
)
response = request.execute()
- Result (copy and paste a JSON response you received)
{{'kind': 'youtube#caption', 'etag': 'BwLV9L8w2orzDQDKDgYL2jeevrA', 'id': 'AUieDaZtNZ8JOoqqvflaC5y6eh-9U-WXlpEgnISlSTbA6bH-Qn5KV8fjWQyi', 'snippet': {'videoId': 'UdJr2p5RrF0', 'lastUpdated': '2024-12-06T14:20:22.988179Z', 'trackKind': 'standard', 'language': 'sv', 'name': 'sv_caption', 'audioTrackType': 'unknown', 'isCC': False, 'isLarge': False, 'isEasyReader': False, 'isDraft': True, 'isAutoSynced': False, 'status': 'serving'}}
- Expected result
I cannot find that in the docs, so I was hoping to see in the video that I can choose another closed caption. Or, see it in youtube studio
- Is it 100% reproducible?
Yes
- Reproducible API explorer link
Do not have