首页 文章

Facebook视频源网址未显示在FB图形api调用中

提问于
浏览
0

我想在FB中直接获取公共视频的网址 .

根据这个问题的建议,

How can I download a video from Facebook using GraphAPI?

我试图调用以下字段 . sourcestatustitle 使用以下网址

https://graph.facebook.com/10158167232321509?access_token=xxxxxx&fields=source,status,title

只返回 statustitleid . 没有视频源网址 .

基于 documentationhttps://developers.facebook.com/docs/graph-api/reference/video/

source 应为 string 类型,包含原始可播放视频文件的A URL .

知道为什么它没有显示源URL吗?

谢谢

2 回答

  • 1

    知道为什么它没有显示源URL吗?

    很可能是因为你没有“在CNN工作......”?

    正如https://developers.facebook.com/docs/graph-api/reference/video/#Reading明确指出的那样,

    除非发出请求的用户在拥有的页面上有角色,否则不会为页面拥有的视频返回源字段 .

  • 2

    在Facebook最新的API更改后,我遇到了同样的问题 . 我提出的解决方案是解析视频的URL,我正在使用以下功能 .

    function getFacebookVideoFromUrl($url) {
        $context = [
            'http' => [
            'method' => 'GET',
            'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.47 Safari/537.36",
            ],
        ];
        $context = stream_context_create($context);
        $data = file_get_contents($url, false, $context);
    
        $regex = '/hd_src_no_ratelimit:"([^"]+)"/';
        if (preg_match($regex, $data, $match)) {
            return $match[1];
        } else {
            $regex = '/sd_src_no_ratelimit:"([^"]+)"/';
            if (preg_match($regex, $data, $match)) {
                return $match[1];
            }
        }
    
        return false;
    }
    

相关问题