Facebook通过Graph API上传视频字幕的功能不起作用

时间:2018-12-17 18:58:21

标签: ruby facebook-graph-api httprequest

我正在尝试通过图形API向视频添加字幕(.srt文件),但是我收到来自Facebook的以下回复

{"error"=>{"message"=>"(#385) The captions file you selected is in a format that we don't support.", "type"=>"OAuthException", "code"=>385, "error_user_msg"=>"The captions file you selected is in a format that we don't support.", "fbtrace_id"=>"HIxy-mhlpHo"}}

下面是我用来在ruby中上传字幕的代码

subtitle_stream = open(subtitle_url)
subtitle_file = File.open('subtitle.en_US.srt', 'w+b') do |file|
      subtitle_stream.respond_to?(:read) ? IO.copy_stream(subtitle_stream, file) : file.write(subtitle_stream)
      open(file)
  end
subtitle_file_obj = UploadIO.new(
              subtitle_file,
              'application/octet-stream',
              'subtitle.en_US.srt'
            )
url = "https://graph.facebook.com/v3.2/3344xxxxx/captions"
uri = URI.parse(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  upload_request = Net::HTTP::Post::Multipart.new uri.request_uri, {
              'access_token' => access_token,
              'captions_file'   => subtitle_file_obj,
            }
  upload_response = http.request(upload_request)

我已使用以下链接中的示例srt文件进行测试

https://fastapi.metacpan.org/source/MIYAGAWA/Video-Subtitle-SRT-0.01/t/sample.srt

0 个答案:

没有答案