6

I'm using FB.ui method to post 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'm able to post image successfully, but couldn't post video. I have tried, but failed.

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
});

above approach is posting feed, I'm looking video should play on facebook only instead of taking link of page.

I am not sure whether I'm missing something on video post OR approach it self wrong.

Could someone help on video, I would really appreciate.

Thanks

Shivakumar P
  • 113
  • 1
  • 7

1 Answers1

6

You can upload videos to Facebook, using the Graph API, in multiple ways. You can have resumable and non-resumable uploads.

The latter is the easiest; you post to graph-video.facebook.com and the video data must be multipart/form-data encoded. The files are limited to 1GB in size and 20 minutes long.

You can upload videos using the SDKs. 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 info. Alternatively, if the video is already uploaded somewhere, you can use the file_url parameter to provide a link to that video.

Please note: the JS SDK default to graph.facebook.com, but you need to post to graph-video.facebook.com. So either you need to override the domain, or re-create the post with a normal JS http request. In that case, use the source parameter and add your access_token in a parameter with that name.

If you have more control over your video files and the process, you can upload the files in chunks. That will allow you to recover from lost upload segments, without the need to re-upload the whole file.

Roemer
  • 3,566
  • 1
  • 16
  • 32
  • what if we want to show progress bar during the large video upload how we can do that in the browser using JavaScript api.? – Muhammad Usama Mashkoor Mar 15 '18 at 11:16
  • The link you are referring to, doesn't that require authenticating the user first, get an access token and such? How can I upload a video without obtaining a access token, just like sharing on youtube but then actually uploading the video instead of sharing a link. – CularBytes Dec 11 '18 at 20:16
  • Which permission is needed to make this request? I am asking my users to give me `user_videos` and `publish_video` permissions but even then I receive a `(#100) No permission to publish the video` error when making a post request. My FB application is in development mode and I am testing with the admin user of that application. The documentation that is linked in the answer is silent about required permission to post video to user timeline. – Waseem Aug 05 '20 at 11:11