Wayne
Wayne

Reputation: 793

Facebook video source url not showing in FB graph api call

I am trying to get direct url of public videos in FB.

Following recommendation in this question,

How can I download a video from Facebook using GraphAPI?

I tried to invoke for the following fields. source, status, title using below url

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

only return status, title and id. No video source url.

Based on the documentation, https://developers.facebook.com/docs/graph-api/reference/video/

source should be a string type containing A URL to the raw, playable video file.

Any idea why it is not showing source url?

thanks

Upvotes: 1

Views: 3389

Answers (2)

sdiama
sdiama

Reputation: 41

I faced the same problem after the latest API changes from Facebook. The solution I came up, was to parse the video's URL and I'm using the following function.

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

Upvotes: 4

C3roe
C3roe

Reputation: 96413

Any idea why it is not showing source url?

Most likely because you don’t “work at” CNN ...?

As https://developers.facebook.com/docs/graph-api/reference/video/#Reading clearly states,

The source field will not be returned for Page-owned videos unless the User making the request has a role on the owning Page.

Upvotes: 3

Related Questions