我想在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 :(得分: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);