2

I am trying to upload captions to YouTube using the Data API. However I can't find in the reference or in the forum any example in Ruby. In specific how to send the actual caption file (xml).

body = {
    :snippet => {
      :videoId => videoId,
      :language => "English",
      :name => "English"
    }
  }
  captions_insert_response = client.execute(
    :api_method => youtube.captions.insert,
    :parameters => {
      :part => body.keys.join(',')
    },
    :body_object => body
  )

where and how do I add the caption file? I tried doing it like uploading a video, but it didn't seem to work. This line was added after ":body_object"

:media => Google::APIClient::UploadIO.new(captions_file, 'text/xml')

Thanks

sebastian
  • 31
  • 5

1 Answers1

0

I solved the issue changing the language in the snippet to "en". This is the complete request if someone needs it.

body = {
    :snippet => {
      :videoId => videoId,
      :language => "en",
      :name => "English"
    }
  }
  captions_insert_response = client.execute(
    :api_method => youtube.captions.insert,
    :body_object => body,
    :media => Google::APIClient::UploadIO.new(captions_file, 'text/xml'),
    :parameters => {
      'uploadType' => 'multipart',
      :part => body.keys.join(',')
    }
  )
sebastian
  • 31
  • 5
  • Trying to implement same feature, but each time receive error `insufficientPermissions`. May be you have ideas why? – Ponf Dec 15 '15 at 16:55
  • 1
    When getting your client and youtube objects (authentication) use the scope="https://www.googleapis.com/auth/youtube.force-ssl". That should give you the necessary permissions. Let me now if you need any more help – sebastian Dec 16 '15 at 14:11
  • Thanks! With scope it works fine! Now I have next error :( I'm using flag `:sync => true` because I'm uploading raw text and want YouTube to set timestamps automatically. I successfully upload subtitles, see them in web UI, and can download same file. But their status is `Track content is not processed` https://s.mail.ru/5M1ERcaaj2o7/img-2015-12-16-17-49-12.png :( – Ponf Dec 16 '15 at 14:50
  • But when I add same file manually via web UI it processed fine – Ponf Dec 16 '15 at 14:51
  • I've never tried uploading wit :sync=>true. The error message makes me think maybe YouTube is still processing the file. Give it a couple minutes and see what happens – sebastian Dec 16 '15 at 15:01
  • I have wait for several hours :( It looks like it's popular problem: http://stackoverflow.com/questions/31408873/php-youtube-v3-api-captions-upload-with-sync-flag/31844857 – Ponf Dec 16 '15 at 15:03