2011-05-23 65 views
1

是否可以使用JavaScript SDK通过Graph API将视频上传到Facebook?通过Graph API上传Facebook视频Javascript SDK

这样的事情...

FB.api('/me/videos', 'post', {message: "Test", source: "@http://video.link.goes/here.flv", access_token: "token"}, function(response) { 
    console.log(response) 
}); 

现在我知道,这是不行的,但有没有办法实现这样的使用图形API和JavaScript SDK?

如果不是,那么使用旧的REST api上传视频剪辑是否安全?因为它将很快被弃用。

Thanx提前!

回答

1

是的,您可以将此发布数据发布到iframe,如here,或者您可以使用jQuery File Upload。 问题是你无法从iframe获得响应,使用插件你可以使用页面句柄。 示例:

<form id="fileupload" action="https://graph-video.facebook.com/me/videos" method="POST" enctype="multipart/form-data"> 
    <input type="hidden" name="access_token" value="user_access_token"> 
    <input type="text" name="title"> 
    <input type="text" name="description"> 
    <input type="file" name="file"> <!-- name must be file --> 
</form> 


<script type="text/javascript"> 

    $('#fileupload').fileupload({ 
     dataType: 'json', 
     forceIframeTransport: true, //force use iframe or will no work 
     autoUpload : true, 
     //facebook book response will be send as param 
     //you can use this page to save video (Graph Api) object on database 
     redirect : 'http://pathToYourServer/videos?video=%s' 
    }); 
</script> 
+0

您说Facebook回复将作为参数发送。你能详细说明一下吗? param和json有什么区别? – picardo 2013-11-17 00:14:14

+0

另外,我想你在你的例子中拼错了access_token字段的名字。 – picardo 2013-11-17 00:49:18

+0

@picardo感谢您的纠正。当上传的视频完成时,facebook将重定向到您在重定向参数中通知的页面,视频参数将为video_id。 – 2013-11-18 12:49:02