facebook video upload错误1363030

时间:2016-01-14 06:04:46

标签: javascript facebook

当我尝试上传时,出现以下错误:

Error code:1363030,
msg: Your video upload timed out before it could be completed. This is probably because of a slow network connection or because the video you're trying to upload is too large. Please try again.

我正在使用Facebook Javascript SDK 2.5。 我错过了什么或错了什么?

<script>
      var files;
      var fileData = '';  
      function handleFileSelect(evt) {
        files = evt.target.files; // FileList object
        var input = evt.target;
        var reader = new FileReader();
        reader.onload = function (e) {
          fileData = e.target.result;
        };
        reader.readAsDataURL(input.files[0]);
        // files is a FileList of File objects. List some properties.
        var output = [];
        for (var i = 0, f; f = files[i]; i++) {
          output.push('<li class="list-group-item">', escape(f.name), '(', f.type || 'n/a', ') - ',
                      f.size, ' bytes','</li>');
        }
        document.getElementById('list').innerHTML = output.join('');
      }
      document.getElementById('files').addEventListener('change', handleFileSelect, false);

      $(document).ready(function()
      {

        $("#upload").click(function(){
          var token = $('#token').val();
          FB.api(
            "/me/videos",
            "POST",
            {    
                "access_token" : token,
                "title" : 'test',
                "source": fileData
            },
            function (response) {
              if (response && !response.error) {
                /* handle the result */
              }
            }
          );
        })

    });
</script>

这是示例site

1 个答案:

答案 0 :(得分:2)

在Node.js中点击这个。如果您没有指定附加文件的内容类型和文件名(即,如果您将其作为内联字段值传递,而不是作为附加文件),则会出现此Facebook错误。

不确定如何通过FB.api执行此操作,但使用request-promise模块(以及通过Babel的ES7异步功能),它看起来像这样:

import request from 'request-promise'

async function uploadVideoToFacebook (buf) {
  let url = 'https://graph-video.facebook.com/v2.5/' + pageId + '/videos?access_token=' + pageToken

  let formData = {
    title: 'Video title',
    description: 'Timeline message...',
    source: {
      value: buf,
      options: {
        filename: 'video.mp4',
        contentType: 'video/mp4'
      }
    }
  }

  return await request({ method: 'POST', url, formData })
}

并且在客户端使用XMLHttpRequest,您可以执行以下操作:

var blob = new Blob(videoDataHere, { type: 'video/mp4' })

var formData = new FormData();
formData.append('source', blob);
formData.append('message', 'Spartan Overlay');

var ajax = new XMLHttpRequest()
ajax.onreadystatechange = ...
ajax.open('POST', 'https://graph.facebook.com/' + userId + '/videos?access_token=' + accessToken, true)
ajax.send(formData)