使用Graph API Facebook获取视频源URL

时间:2014-10-22 21:28:58

标签: javascript facebook facebook-graph-api

我希望使用Javascript SDK获取带有Graph API的视频源网址

这是我使用视频对象的默认代码构建的

function getVideo(id) {
var vid = id;
FB.api(
"video/{vid}",
function (response) {
  if (response && !response.error) {
    var v = "source": source;
    alert(v);
  }
}
);
}

2 个答案:

答案 0 :(得分:1)

您需要使用端点

/{video_id}

而不是

/video/{video_id}

https://developers.facebook.com/docs/graph-api/reference/v2.1/video/

的文档中明确说明了这一点

您的代码需要

function getVideo(id) {
    FB.api("/"+id, function (response) {
        if (response && !response.error) {
            alert(response);
        }
    });
}

答案 1 :(得分:0)

您可以通过API

再申请一个额外的字段参数
  

$ pageid =“YOURPAGENAME”;

     

$ facebook-> api(“/”。$ pageid。“/ feed?fields = location& locale = en_GB& fields = type,message,id,story,link,created_time,attachments,source,name,picture ,的object_id,地点&安培;限制= 20" );

source =>将返回url mp4视频帖子

并确保您将在附件数组中看到类型

[type] => video_inline / video_share_youtube

您将获得两种类型的视频网址:

https://video.xx.fbcdn.net/v/t42.1790-2/xxxxxxx8431328184267440128_n.mp4

https://www.youtube.com/embed/xxxxxxxxxx?autoplay=1