2013-07-24 36 views
1

我想在Facebook上分享視頻/音頻任何類型的文件。
我可以分享狀態或其他所有的東西,除了音頻/視頻。我在鈦工作。這裏是我的代碼如何使用鈦Appceller創建的iPhone應用程序在Facebook上共享視頻/音頻文件

login.addEventListener('click', function(e){ 
    Titanium.Facebook.authorize(); 
    var f=Titanium.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory+"/"+"audio"+"/"+"abc.mp4"); 
    var blob=f.nativePath; 
    alert(blob); 
    var data={ 
    message: 'Check this video!',  
    video: blob 
    } 

    Titanium.Facebook.requestWithGraphPath('me/videos', data, 'POST', function(e) { 
     if (e.success) 
      { 
       alert("Success! From FB: " + e.result); 

      } else if (e.error) { 
       alert(e.error); 
      } else { 
       alert('Unknown response.'); 
      } 
    }); }); 

回答

0

你只傳遞文件路徑(nativePath)給Facebook,而是試圖通過實際的圖像斑點這樣的:

var blob=f.read(); 
var data={ 
    message: 'Check this video!',  
    video: blob 
} 
// The rest.... 
+0

嘿喬西亞海絲特,我已經試過f.read(),我也給硬編碼路徑的數據,但它仍然不會工作.. –

0

下面是答案#

  var url = "https://graph-video.facebook.com/me/videos"; 
      Titanium.Facebook.authorize(); 
      var xhr_video = Titanium.Network.createHTTPClient(); 

      xhr_video.open('POST', url); 

      xhr_video.setRequestHeader('Content-Type', 'multipart/form-data'); 

      xhr_video.onload = function(e) { 

       alert("Video Has Been Successfully Posted to Your Timeline"); 

      }; 
      xhr_video.onerror = function(e) { 
       alert(e); 
       xhr_video.abort(); 

      }; 
      var f=Titanium.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory+"/"+"audio"+"/"+"video.mp4"); 
       var blob=f.read(); 
      var data = { 
       video : blob, 
       //access_token : Titanium.Facebook.getAccessToken() 
       access_token:Ti.Facebook.accessToken 
      }; 
      alert(data); 
      xhr_video.send(data); 
相關問題