如何在使用钛金属加速器创建的iPhone应用程序在Facebook上分享视频/音频文件

时间:2013-07-24 09:23:44

标签: javascript iphone facebook titanium sharing

我想在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.');
            }
    });  });

2 个答案:

答案 0 :(得分:0)

您只是将文件路径(nativePath)传递给Facebook,而是尝试传递实际的图像blob:

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

答案 1 :(得分: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);