5

I've been trying to insert a caption into an existing video on youtube. I was able to call the List caption endpoint with no problem. So this is not an Auth issue.

I called the POST https://www.googleapis.com/youtube/v3/captions?part=snippet

with a request body

{
  "snippet": {
    "language": "en",
    "name": "English captions",
    "videoId": "MY_VIDEO_ID",
    "isDraft": true
   }
} 

But I'm getting a "The request does not contain the caption track contents."

https://developers.google.com/youtube/v3/docs/captions/insert

The google api explorer does not show u how to actually attach the caption file on the request.

I tried posting using form data too, but no luck.

Tommy
  • 979
  • 8
  • 15

1 Answers1

1

You have to add a separate argument called "media_body".

request = youtube.captions().insert(
    part="snippet",
    body={
      "snippet": {
        "language": "en",
        "name": "English captions",
        "videoId": "MY_VIDEO_ID"
      }
    },
    media_body=MediaFileUpload("whateverfile.extension")
)

For further reference, when checking something in the YouTubeAPI docs, go to the "Try this method" feature. Any missing arguments (like in this case) will be shown there even if they are not in the docs.

Peibol
  • 11
  • 2
  • There is no mention of media_body in Google's docs, and it is not included in the "Try this method" feature, either. https://developers.google.com/youtube/v3/docs/captions/insert – qel Aug 25 '23 at 07:21