如何使用FB.ui Javascript sdk在Facebook上传视频 [英] How to upload video on facebook using FB.ui Javascript sdk

查看:153
本文介绍了如何使用FB.ui Javascript sdk在Facebook上传视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FB.ui方法将图片发布到Facebook,如下所述:

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

以上方法是发布Feed,我看视频应该只在facebook上播放而不是取得链接页面。

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.

谢谢

推荐答案

您可以通过多种方式使用Graph API将视频上传到Facebook。您可以 resumable 不可恢复上传。

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

后者是最简单的;你发布到 graph-video.facebook.com ,视频数据必须是 multipart / form-data 编码。这些文件的大小限制为 1GB 20分钟长。

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.

您可以使用SDK上传视频。例如,以下代码将使用JS SDK:

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

此处来源参数是您的编码视频文件。有关详细信息,请参阅文档。或者,如果视频已在某处上传,您可以使用 file_url 参数提供该视频的链接。

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.

请注意: JS SDK默认为 graph.facebook.com ,但您需要发布到 graph-video.facebook.com 。因此,您需要覆盖域,或者使用正常的JS http请求重新创建帖子。在这种情况下,使用 source 参数在参数中添加 access_token 名称。

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.

如果您可以更好地控制视频文件和流程,可以在 chunk 。这样您就可以从丢失的上传段中恢复,而无需重新上传整个文件。

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.

这篇关于如何使用FB.ui Javascript sdk在Facebook上传视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆