2016-01-14 103 views
2

當我嘗試上傳,我得到以下錯誤:Facebook的視頻上傳錯誤1363030

 
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

+0

那麼你的視頻太大了,或者你的上傳速度很慢? –

+0

它的小小於200kB的測試我上傳 這是我的速度測試 http://www.speedtest.net/my-result/4995493200 –

+0

這裏沒有涉及到實際問題,只是一個提示:您可以讓數據生成很簡單,如果你只是使用['FormData'](https://developer.mozilla.org/de/docs/Web/API/FormData)對象。這樣,您不必自己閱讀文件內容,製作它的數據URI等。 – CBroe

回答

2

在Node.js的只要按下此如果您未指定附加文件的內容類型和文件名(即,如果您將它作爲內聯字段值傳遞,而不是附加文件),則會發生此Facebook錯誤。

不知道如何通過FB.api做到這一點,但request-promise模塊(和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)