How to upload video to facebook using FB.ui Javascript sdk

I use the FB.ui method to send the image to facebook, as described below:

FB.ui({ display: 'popup', method: 'feed', name: 'image', link: 'link', picture: 'image path', caption: 'caption', description: 'description' }, function(response){ // do something }); 

I can send the image successfully, but could not post the video. I tried, but could not.

 FB.ui({ display: 'popup', method: 'feed', link: 'link', picture: 'thumbnail image path', source: 'https://example.com/media/video.mp4', caption: 'caption', description: 'description' }, function(response){ // do something }); 

the above approach is to send the feed, I am looking for a video to play on facebook only instead of the link to the page.

I'm not sure if I missed something in the video position or I'm not mistaken.

Did anyone help on the video, I would really appreciate it.

thanks

+5
source share
1 answer

You can upload videos to Facebook using the Graph API in several ways. You can resume and not resume downloads.

The latter is the simplest; you send a message to graph-video.facebook.com, and the video data must be multipart/form-data encoded. Files are limited to 1 GB in size and 20 minutes in length.

You can upload videos using the SDK . For example, the following code will use the JS SDK:

 /* make the API call */ FB.api( "/{user-id}/videos", "POST", { "source": "{video-data}" }, function (response) { if (response && !response.error) { /* handle the result */ } } ); 

Here, the source parameter is your encoded video file. See the docs for more information. Alternatively, if the video has already been downloaded somewhere, you can use the file_url parameter to provide a link to this video.

Note: the default JS SDK is graph.facebook.com, but you need to send a message to graph-video.facebook.com. So you need to redefine the domain or re-create the message with a regular JS HTTP request. In this case, use the source parameter and add access_token to the parameter with this name.

If you have more control over your video files and process, you can upload files to chunks . This will allow you to recover from lost download segments without having to re-download the entire file.

+4
source

All Articles