How To Display Facebook Page Videos On Website Using PHP?


In this tutorial, I will show you how to display Facebook page videos on website using PHP.

Videos from your Facebook page are not shown to your website visitors. You spend a lot of time creating, editing, and managing your videos. But the fans, audience, and customers from your website still do not see your Facebook videos.

Our code in this tutorial will allow you to automatically display your Facebook page videos on your website using PHP. Upload your videos on Facebook and it will also appear automatically on your website.

Source Code Overview

This code will get the list of videos from your Facebook page with data such as the video itself, video title, description, date posted, etc. from your Facebook fan page without using any Facebook PHP SDK, just the Facebook Graph API!

We will display these videos to a webpage (assuming it is your WordPress or PHP website.)

We will use a user interface powered by Bootstrap. If you’re not yet familiar with this awesome front-end framework, see our step by step Bootstrap tutorial here.

Don’t want to code?

Before we continue coding, if you later realize you do not want to code and need more features, you can use a website plugin called SociableKIT. It is the best no-code tool for the job.

You can easily customize the look and feel of your Facebook page video feed and embed it on your website in 3 minutes. The videos feed on your website will update automatically.

Follow this tutorial: Embed Facebook page videos on website. You can also embed Facebook page live streams and Facebook page playlist videos. There’s a free plan that you can use if you don’t need the premium features of SociableKIT.

Display Facebook Page Videos on Website – Output

BASIC Source Code Output

We have to know where we are going, if we’re done with the code tutorial below, we will achieve this output:

PRO Source Code Output

We used PHP classes and so features are easier to use, more actively improved and added.

See the full list of features in section 10.1 to 10.3 below. It has all the details of these features.

For now, let us learn how the BASIC source code was made. Enjoy the following step by step tutorial!

Get your page access token

Before you can get any data from your Facebook page via the graph API, you need a “page” access token.

Follow this detailed tutorial about how to get a page access token: How to get a Facebook page access token?

Replace YOUR_ACCESS_TOKEN with your page access token.

Create index.php

Create index.php and set the timezone, Facebook page and the page title. Put the following code inside index.php

// set timezone for servers that requires it

// set Facebook page ID or username
$fb_page_id = "katyperry";

// page title
$page_title = "BASIC - Display Facebook Page Videos on Website";

Enable Bootstrap

Put a Bootstrap-enabled basic HTML after the code on section 4.0.

<!DOCTYPE html>
<html lang="en">

    <meta charset="utf-8">
    <http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title><?php echo $page_title;></title>

    <link rel="stylesheet" href="//">


<div class="container">

</div> <!-- /container -->

<script src=""></script>
<script src="//"></script>

<--[if lt IE 9]-->
<script src=""></script>
<script src=""></script>


Specify Variables

Specify the values for the following variables:

  • $profile_photo_src so that the Facebook page primary picture will be rendered in thumbnail.
  • $access_token obtained on section 3.0, this will give us the power to get Facebook page videos.
  • $fields are actually column names in Facebook page videos database.
  • $limit the number of videos you want to be displayed on your page.

Put the following code inside the ‘container’ tags on section 5.0

$profile_photo_src = "{$fb_page_id}/picture?type=square";
$access_token = "YOUR_ACCESS_TOKEN ";
$fields = "id,title,description,created_time,from,source";
$limit = 5;

Build JSON Link

Use the variable values on the previous section and construct the $json_link. Get the data from that URL, decode it, and count the number of records it returned.

In short, put the following code after the code in section 6.0

$json_link = "{$fb_page_id}/videos?access_token={$access_token}&fields={$fields}&limit={$limit}";
$json = file_get_contents($json_link);

$obj = json_decode($json, true);
$feed_item_count = count($obj['data']);

Loop Through Videos

Loop through each records, extract each video information and place it in an HTML structure.

for($x=0; $x<$feed_item_count; $x++){
	echo "<div class='row'>";
		// video source
		$source = $obj['data'][$x]['source'];

		// display Facebook page video
		echo "<lt;div class='col-md-6'>";
			echo "<video controls class='embed-responsive-item'>;
				echo "<source src={$source} type=video/mp4>";
			echo "</video>";
		echo "</div>";

		echo "<div class='col-md-6'>";

			// user's custom message
			$title = isset($obj['data'][$x]['title'])
						? htmlspecialchars_decode($obj['data'][$x]['title'])
						: "Video #" . $obj['data'][$x]['id'];

			$description = isset($obj['data'][$x]['description']) ? $obj['data'][$x]['description'] : "";
			$description = htmlspecialchars_decode(str_replace("\n", "<br>", $description));

			// when it was posted
			$created_time = $obj['data'][$x]['created_time'];
			$converted_date_time = date( 'Y-m-d H:i:s', strtotime($created_time));
			$ago_value = time_elapsed_string($converted_date_time);

			// from
			$page_id = $obj['data'][$x]['from']['id'];
			$page_name = $obj['data'][$x]['from']['name'];

			// display video title
			echo "<h2 style='margin: 0 0 .5em 0;'>{$title}</h2>";

			// display video description
			echo "<div>";
				echo $description;
			echo "</div>";

			// display when it was posted
			echo "<div style='margin:.5em 0 0 0; color: #999;'>";
				echo "Posted {$ago_value} by <a href='{$page_id}' target='_blank'>{$page_name}</a>";
			echo "</div>";

		echo "</div>";

		echo "<div class='col-md-12'>";
			echo "<hr style='margin:2em 0; border:thin solid #f1f1f1;' />";
		echo "</div>";
	echo "</div>";

Format Post Date

time_elapsed_string() is a function that will return the “time ago” value, from section 8.0, we pass when the video was posted so that we can display something like: 9 days ago, 9 months ago, a year ago, etc…

Put the following code after the closing ‘html’ tag.

// to get 'time ago' text
function time_elapsed_string($datetime, $full = false) {

	$now = new DateTime;
	$ago = new DateTime($datetime);
	$diff = $now->diff($ago);

	$diff->w = floor($diff->d / 7);
	$diff->d -= $diff->w * 7;

	$string = array(
		'y' => 'year',
		'm' => 'month',
		'w' => 'week',
		'd' => 'day',
		'h' => 'hour',
		'i' => 'minute',
		's' => 'second',
	foreach ($string as $k => &$v) {
		if ($diff->$k) {
			$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
		} else {

	if (!$full) $string = array_slice($string, 0, 1);
	return $string ? implode(', ', $string) . ' ago' : 'just now';

Download the Complete Source Code

You can get the source code for free by following the whole, well detailed tutorial above. But isn’t it more convenient if you can just download the complete source code we used, and play around it?

There’s a small fee in getting the complete source code, it is small compared to the value or skill upgrade it can bring you, or income you can get from your website project or business.

For a limited time only, I will give you the source code for a low price. DOWNLOAD THE SOURCE CODE by clicking the green buy button below.

Download BASIC Source Code

Upload videos on your Facebook page, watch them on your website. YES
Save time figuring out and coding these features on your website. YES
Display video list from your Facebook page. YES
Display video title. If none, display video number. YES
Display video description. YES
Post date with “time ago” format. YES
Display Facebook page name (with link) for each video. (opens in new tab) YES
Bootstrap enabled script. YES
Responsive layout. (great for mobile devices) YES
Free source code updates. YES
Free support for 6 months. YES
Download Now

Download the PRO Source Code

All features of BASIC source code. YES
Display number of likes. YES
Display number of comments. YES
Display some likers and link to their profiles. YES
Display commenters and link to their profile. YES
Display user comments. YES
Show comments and comment replies on pop up. YES
Load more videos automatically when scrolling (infinite scroll). YES
Newly loaded content still has video controls, number of likes, etc. YES
Will say “All videos were loaded.” when there’s no content to be loaded. YES
Make links clickable in video description. YES
Make links clickable in user comments. YES
Link to actual Facebook page video post. YES
Likers and commenters are loaded and shown via AJAX YES
Show comments YES
Show more comments, loaded via AJAX YES
Show comment replies YES
Show more comment replies, loaded via AJAX YES
Made with PHP classes YES
Useful class methods & properties YES
4-step easy integration to your website YES
Free support for 1 year. YES
Free source code updates. YES
Download Now

Need more reasons to download?

Buy only once, use on unlimited number of websites and Facebook pages! YES
No different kind of licenses. YES
No many different pricing schemes. YES
No monthly or any recurring fees. YES
No need to rely on another website to render Facebook page videos. YES
No need for codes from other websites. YES
You can learn more how to code, I love teaching and can give you free tips! YES
Familiarize yourself with the Facebook Graph API. YES
You get free code and feature updates YES
Tutorial above is always free and updated every Facebook API update. YES
Completely customizable. YES

If you think there’s a missing feature, please let us know by sending me a message via email [email protected], or via our official Facebook page! We can work on it!

Thank you for supporting our projects here at!

Please provide your Facebook page URL on the message, thanks!

What’s Next?

Today we have learned how to show your Facebook page videos on your website.

Did you know that you can also display Facebook Timeline feed on your website?

Let us go to the next tutorial: How To Display Facebook Page POSTS on Website?

Related Source Codes

Did you know that you can also display other social media data on your website? I’ve created tutorials on them too, see the following:

Social Media Script Tutorials
Display Facebook Page EVENTS on Website
Display Facebook Page PHOTOS on Website
Display Facebook Page VIDEOS on Website
Display Facebook Page POSTS on Website
Display Instagram FEED On Your Website
Display Twitter FEED on Website
Display Google+ FEED on Website

Some Notes

#1 Found An Issue?

If you found a problem with this code, we can solve it faster via Email or FB message, please send me a message via email [email protected], or via our official Facebook page!

Please be more detailed about your issue. Best if you can provide an error message and your test or page URL. Thanks!

Please feel free to comment if you have any questions, suggestions, found something wrong or want to contribute to this code.

#2 Become a true Ninja!

  • 1. Subscribe to social media scripts tutorial news and updates.
  • 2. Be updated about what works and what does not work on social media APIs.
  • 3. Be notified for any related social media API updates.
100% Privacy. We will never spam you!

#3 Thank You!

Thanks for visiting our tutorial on how to display Facebook page videos on website using PHP and Facebook Graph API!

By Mike Dalisay

I'm Mike Dalisay, a pro web developer since 2010. I love web development. Improving our tutorials and source codes makes me happy. Do you want to suggest an edit to our tutorial? Got something to ask about our source codes? You may use our comments section below or email our team at [email protected]


  1. $json = file_get_contents($json_link);
    is not accepted some webhosting companies for security reason, can you please make it in Curl format, I really need it but don’t know how to convert it to Curl

    1. Hello @Ali, I cannot add the cURL version for now but I believe a script like this will get you started:

      function file_get_contents_curl($url) {
      $ch = curl_init();

      curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

      $data = curl_exec($ch);

      return $data;

      Another solution is to find a web hosting provider that can secure the file_get_contents() PHP function.

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top