Here in codeofaninja.com, we work hard to produce scripts that works - scripts that are truly useful for your projects or business.
Downloading this LEVEL 3 PRO PACK now will give you the same features and quality support as if you buy them one by one. The only difference is you get a huge discount.
This pack contains five LEVEL 3 social media scripts we have. If you will buy them all one by one, it will cost you $249.95.
But, if you will download this pack, it will be $198 only. You just saved $51.95!
If you will buy our LEVEL 3 PRO PACK now, you will get two LEVEL 2 scripts as well! These scripts are worth another $59.98 and you get it at no extra cost!
This time, instead of spending $309.93, you still get it for $198. You just saved $111.93!
★★★★★ “Hi Mr. Dalisay, My name is Clinton and I’m a front end designer. I purchased two (Facebook) scripts from you today. Thank you for your time and what a great tutorial and was happy to support your projects.”
★★★★★ “This guy is the best. There was a small issue and he helped me right away. I recommend this (Facebook Feed) script to everybody. Instead of wasting time by copy pasting, just purchased the package and saved a lot of time.”
★★★★★ “Just wanted to say thank you. Just purchased the (Social) Script PRO Pack today not too long ago and modified it a bit to make it a dark theme and it’s working great. It saved me A LOT of time! Thank you!!!!!!!”
If you previously bought any scripts here in codeofaninja.com, we'll give you another 15% off today!
Just send me an email ([email protected]) with a subject "DISCOUNT REQUEST: Social Media Scripts – LEVEL 3 – PRO PACK" and I'll reply with the discount code.
You don't like to code? No problem!
You demanded it, we built it. A lot of people requested a website plugin version of our social media scripts. Now it is available. It works no matter what website platform you use. We have tried it in WordPress, Squarespace, Wix and more.
Thank you for supporting codeofaninja.com!
If you have any questions or if there's anything else I can help you with, please do not hesitate to send me an email. My email address is [email protected]
You can use the comment box below as well.
https://i0.wp.com/www.codeofaninja.com/wp-content/uploads/2016/08/social-media-scripts-level-3-pro-pack-w-btn.jpg?fit=1200%2C628&ssl=16281200Mike Dalisayhttps://www.codeofaninja.com/wp-content/uploads/2019/03/codeofaninja-with-text-3-1030x206.pngMike Dalisay2016-08-12 00:27:302021-07-22 09:13:24Download The Social Media Scripts – LEVEL 3 – PRO PACK
Today, this tutorial will help you learn how to display a Twitter feed on your website using PHP. Twitter is a powerful tool for businesses and individuals looking to promote their brands or products.
If you're running a website for your brand, it makes sense to incorporate your Twitter feed into your website. This allows your followers to stay updated with your latest tweets without ever having to leave your site.
However, the standard Twitter widget may not always be the best fit for your website's design. That's why we'll show you how to customize the look and feel of your Twitter feed to match your website's design scheme.
You'll learn how to retrieve tweets, format them, and display them on your website using PHP. So, whether you're a developer or just looking to add this feature to your website, this tutorial is for you.
Don't want to code?
Before we start coding, you might be someone not really interested in coding. Or, you just want a quick solution to adding a Twitter feed to your website.
If that's the case, you need to use a "no code" approach. One way of doing it is to use a website plugin called SociableKIT. It is a free website plugin that allows you to embed your Twitter feed on your website. No coding is required.
Let's go back to coding below.
Source Code Overview
Here’s an overview of what our code does:
It gets a Twitter users' profile information and posts from a specified Twitter account. We'll try Taylor Swift's Twitter account in the demo.
Display these Twitter data on a webpage (assuming it is your WordPress or PHP website.)
Show some awesome UI powered by Bootstrap. If you’re not yet familiar with this excellent front-end framework, see our step by step Bootstrap tutorial here.
Final output
We have to know where we are going. If we're done with the code tutorial in this post, we will achieve this output:
Go back to the twitter apps page, you should see your new app now
Click your app and go to the "Keys and Access Tokens" tab
There you will see the Bearer Token you need:
Bearer Token
Create The index.php File
We will make index.php Bootstrap ready. For those not familiar with the CSS framework Bootstrap, please refer to our step-by-step tutorial here: Step by Step Bootstrap Tutorial for Beginners
The index.php file will have the following code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Display Twitter Feed On Website - LEVEL 2 - Live Demo</title>
<!-- Bootstrap CSS -->
<link href="libs/js/bootstrap/dist/css/bootstrap.css" rel="stylesheet" media="screen">
</head>
<body>
<!-- PAGE CONTENT and PHP CODE WILL BE HERE -->
<!-- jQuery library -->
<script src="libs/js/jquery.js"></script>
<!-- bootstrap JavaScript -->
<script src="libs/js/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="libs/js/bootstrap/docs-assets/js/holder.js"></script>
<!-- HTML5 Shiv and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</body>
</html>
Put Container Tags, Page Title and HTML
We will have the following code inside the "body" tag of our code in section 4.0
<div class="container">
<div class="col-lg-12">
<div class="page-header">
<h1>Display Twitter Feed On Website - LEVEL 1 - Live Demo</h1>
</div>
</div>
<div class="col-lg-4">
<!-- TWITTER USER PROFILE INFORMATION WILL BE HERE -->
</div> <!-- end <div class="col-lg-4"> -->
<div class="col-lg-8">
<!-- TWITTER USER FEED WILL BE HERE -->
</div> <!-- end <div class="col-lg-8"> -->
</div> <!-- end <div class="container"> -->
Specify Keys And Variable Values
The following code will be inside the DIV tag with class="col-lg-4".
Access token and keys value were retrieved during our section 3.0 earlier.
<?php
$tweets = [];
$bio = [];
// max tweet results when retrieving tweets
$max_results = "5";
// get profile username
$username=isset($_GET['username']) ? $_GET['username'] : "SociableKIT_hq";
// data to be retrieve when retrieving profile bio
$bio_fields = 'user.fields=created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,url,username,verified,withheld&expansions=pinned_tweet_id';
// data to be retrieve when retrieving tweets
$tweet_fields = 'tweet.fields=attachments,author_id,context_annotations,conversation_id,created_at,edit_controls,edit_history_tweet_ids,entities,geo,id,in_reply_to_user_id,lang,note_tweet,possibly_sensitive,public_metrics,referenced_tweets,reply_settings,source,text,withheld&expansions=attachments.media_keys,referenced_tweets.id&media.fields=duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width,alt_text';
// bio data url
$bioUrl = "https://api.twitter.com/2/users/by/username/".$username."?".$bio_fields;
// tweets url
$tweetsUrl = "";
// bearer token from your app
$bearerToken = "YOUR_BEARER_TOKEN";
?>
Make The Authorization Request For the Bio
We can now make request to the Twitter API with the bearer token from your app using cURL.
The code below will allow us to retrieve the bio information.
Put the follwing code below our code on section 5.0
// request header to be use, the bearer token will be use here.
$headers = array(
'Authorization: Bearer ' . $bearerToken
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $bioUrl);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// check if request is successful
if ($httpcode >= 200 && $httpcode < 300) {
$original_response = json_decode($response, true);
// store the bio data retrieve from API to the $bio variable
$bio = $original_response['data'];
$profile_id = isset($bio['id']) ? $bio['id'] : "";
$tweetsUrl = 'https://api.twitter.com/2/users/' . $profile_id . '/tweets?' . $tweet_fields . '&max_results=' . $max_results;
} else {
echo 'Error: HTTP ' . $httpcode;
}
);
Make The Authorization Request For the Tweets
We can now make request to the Twitter API with the bearer token from your app using cURL.
The code below will allow us to retrieve the tweets.
Put the follwing code below our code on section 6.0
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $tweetsUrl);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpcode >= 200 && $httpcode < 300) {
$original_response = json_decode($response, true);
// store the tweets data retrieve from API to the $tweets variable
$tweets = $original_response['data'];
} else {
echo 'Error: HTTP ' . $httpcode;
}
curl_close($ch);
Display Twitter User Information
The following code shows how we can display the specified Twitter user's information. Put it below our code on section 9.0
echo "<div class='col-lg-4' style='margin-top:-13.5em;'>";
// show user information
echo "<div class='overflow-hidden bio-container'>";
// user data
$profile_photo = isset($bio['profile_image_url']) ? $bio['profile_image_url'] : "";
$name = isset($bio['name']) ? $bio['name'] : "";
$screen_name = isset($bio['username']) ? $bio['username'] : "";
$location = "";
$description = isset($bio['description']) ? $bio['description'] : "";
$url = isset($bio['url']) ? $bio['url'] : "";
$display_url = isset($bio['url']) ? $bio['url'] : "";
$verified = isset($bio['verified']) ? $bio['verified'] : "";
// show profile photo
echo "<img src='{$profile_photo}' class='img-thumbnail' />";
// show other information about the user
echo "<div class='text-align-center'>";
echo "<div><h2>{$name}</h2></div>";
echo "<div><a href='https://twitter.com/{$screen_name}' target='_blank'>@{$screen_name}</a></div>";
echo "<div>{$location}</div>";
echo "<div>{$description}</div>";
echo "<div><a href='{$url}' target='_blank'>{$display_url}</a></div>";
echo "</div>";
echo "<hr />";
echo "</div>";
Display Twitter Posts / Status Feed
Finally we can now display the user's Twitter posts.
// show tweets
foreach($tweets as $tweet){
// show a tweet
echo "<div class='overflow-hidden'>";
// show picture
echo "<div class='tweet-image'>";
echo "<img src='{$profile_photo}' class='img-thumbnail' />";
echo "</div>";
// show tweet content
echo "<div class='tweet-text'>";
// show name and screen name
echo "<h4 class='margin-top-4px'>";
echo "<a href='https://twitter.com/{$screen_name}'>{$name}</a> ";
echo "<span class='color-gray'>@{$screen_name}</span>";
echo "</h4>";
// show tweet text
echo "<div class='margin-zero'>";
// get tweet text
$date = new DateTime($tweet['created_at']);
$created_at = $utils->getTimeAgo($date->format('F j, Y'));
$tweet_text=$tweet['text'];
// make links clickable
$tweet_text=preg_replace('@(https?://([-\w\.]+)+(/([\w/_\.]*(\?\S+)?(#\S+)?)?)?)@', '<a href="$1" target="_blank">$1</a>', $tweet_text);
// make users clickable
$tweet_text = preg_replace('/@(\w+)/', '<a href="https://twitter.com/$1" target="_blank">@$1</a>', $tweet_text);
// make hashtags clickable
$tweet_text=preg_replace('/\#([a-z0-9]+)/i', '<a href="https://twitter.com/search?q=%23$1" target="_blank">#$1</a>', $tweet_text);
// output
echo $tweet_text;
echo "<div class='color-gray'>{$created_at}</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<hr />";
}
Add Your Custom Styling
The following CSS code is what I used to add a some style on our page. I put it inside the "head" tag, just below the Bootstrap CSS.
Don't just take our word for it. See what our students have to say about our tutorials and source codes. We are proud to have helped many individuals and businesses to build their own applications. Here are a few of the testimonials from our satisfied students.
★★★★★ “Wow, I love you guys! The best web programming tutorial I’ve ever seen. So comprehensive, yet easy to follow. I love how you combine all necessary elements in such a neat structure.” ~ Olaug Nessa
★★★★★ “The fact that you’ve put it all together saves so much time and its worth buying the code. Makes me feel good supporting a developer like yourself. Keep up the good work!” ~ Dan Hudson
★★★★★ “Thanks for making these awesome tutorials! I bought your source codes. To be honest, it’s very readable code and helps me understand a lot of things and how it’s done in PHP. Thanks for that again.” ~ Michael Lammens
★★★★★ “Hey Mike, my name is Leonardo from Argentina. I’ve been reading your blog since like 4 months from now, and I really must say: your tutorials are very good, they has helped me in many of my works… Well, thank you very much man. I really admire your work.” ~ Leonardo
★★★★★ “Words can’t express how grateful I am for the work and the articles you post, had some troubles with doing somethings but your articles as per usual hit the hammer right on the head. They are a great way for expanding upon later too!” ~ Jeremy Smith
Got comments?
At codeofaninja.com, we strive to provide our readers with accurate and helpful Display Twitter Feed on Website Using PHP Your feedback is essential in helping us achieve this goal.
If you have encountered any issues with the code, have suggestions for improvement, or wish to provide praise, we welcome you to leave a comment below. Please be as descriptive as possible to address your concerns effectively and include any relevant error messages, screenshots, or test URLs.
We request that comments remain on-topic and relevant to the article above. If your question or comment pertains to a different topic, we recommend seeking assistance elsewhere.
Furthermore, we ask that you review our code of conduct before commenting to ensure that your feedback is constructive and respectful.
Thank you for taking the time to provide feedback and for supporting codeofaninja.com. Your contributions help us improve our tutorials and serve the developer community better.
Subscribe for FREE!
Improve your web development skills and stay ahead of the competition by subscribing to our tutorial series. Sign up for FREE and access exclusive, cutting-edge content delivered straight to your inbox.
Take advantage of the chance to elevate your skills and advance your web development career. Subscribe now.
Thank You!
We hope you've found our Display Twitter Feed on Website Using PHP helpful and informative. We understand that learning new programming concepts can be challenging, but we're glad we could make it easier for you.
Thank you for choosing to learn with us and for supporting codeofaninja.com! Consider sharing this tutorial with your friends and colleagues who may also be interested in learning about Display Twitter Feed on Website Using PHP
The more people know about our tutorials, the more we can help the developer community grow. Keep learning, keep coding, and keep growing as a developer. We can't wait to see what you'll create next!
https://i0.wp.com/www.codeofaninja.com/wp-content/uploads/2015/08/display-twitter-feed-on-website-1-1.jpg?fit=750%2C393&ssl=1393750Mike Dalisayhttps://www.codeofaninja.com/wp-content/uploads/2019/03/codeofaninja-with-text-3-1030x206.pngMike Dalisay2015-08-14 11:55:142023-11-24 18:53:08Display Twitter Feed on Website Using PHP
Today, our tutorial will explore integrating Instagram into your website by displaying your Instagram feed using PHP. This can be a great way to showcase your content and keep your website visitors engaged with your brand.
Using PHP, we can easily connect to the Instagram API and retrieve your latest posts, allowing them to be displayed on your website. Any new content you upload to Instagram will automatically appear on your website, saving you the hassle of manually updating your website every time you post something new.
Following this tutorial can bring your Instagram content to your website, providing your audience with a seamless browsing experience and keeping them updated with your latest content. So, let's dive in and start displaying your Instagram feed on your website using PHP!
Display Instagram feed on website using PHP
We will use the official Instagram Basic Display API. This API allows users to read basic profile information, photos, videos, and albums of the connected account.
Here are the steps to display the Instagram feed on a website using PHP.
Retrieve long-lived access token.
Use our PHP code to display your Instagram feed.
Use our CSS code to make the display look good.
View our output.
Retrieve your long-lived access token
The long-lived access token is like a key that you will use to retrieve your Instagram photos and videos programmatically. You will use this token on our PHP code later.
Configure Instagram's basic display API. Instagram's documentation is good enough, and I don't want to repeat the exact same instructions here. Follow the guide here.
Get your long-lived access token. By default, Instagram API will give you a short-lived access token that is valid only for 24 hours. If you get your long-lived access token, it will be valid for 60 days. Learn how to get a valid long-lived access token here.
Use our PHP code to display your Instagram feed
Once you get your long-lived access token, use it as the value of the $token variable below. The code below will allow you to display the list of posts
We will also cover using a website plugin to achieve the same output. This is best for people who do not want to code. Continue reading below.
Display Instagram feed using a website plugin
If you do not want to code, use a "no-code" approach. You can use website plugins like SociableKIT. Follow this tutorial: embed your Instagram feed on your website. You can use its free plan if you do not need the premium features.
Step-by-step guide
Follow the steps below to display your Instagram feed using a website plugin.
Sign up for SociableKIT. You will be logged in automatically after you enter your email address.
Create a new solution. Select "Instagram feed" on the drop-down. Enter your Instagram username.
Click the Next button. It will show the customization options like layouts, colors, and more. Click the Save changes button.
Copy embed code. On the upper right, click the "Embed on website" button. Copy the embed code.
Paste on your website. Create a new page or edit an existing page on your website. Paste the embed code where you want the Instagram feed to appear.
Using SociableKIT, you can also display Instagram reels, Instagram hashtag feed, Instagram stories, and more on your website.
Output
Your Instagram feed using SociableKIT can look like the following.
What's Next?
Today we have learned how to show your Facebook page events on your website. Did you know that you can also display a Twitter feed on your website?
Don't just take our word for it. See what our students have to say about our tutorials and source codes. We are proud to have helped many individuals and businesses to build their own applications. Here are a few of the testimonials from our satisfied students.
★★★★★ “Wow, I love you guys! The best web programming tutorial I’ve ever seen. So comprehensive, yet easy to follow. I love how you combine all necessary elements in such a neat structure.” ~ Olaug Nessa
★★★★★ “The fact that you’ve put it all together saves so much time and its worth buying the code. Makes me feel good supporting a developer like yourself. Keep up the good work!” ~ Dan Hudson
★★★★★ “Thanks for making these awesome tutorials! I bought your source codes. To be honest, it’s very readable code and helps me understand a lot of things and how it’s done in PHP. Thanks for that again.” ~ Michael Lammens
★★★★★ “Hey Mike, my name is Leonardo from Argentina. I’ve been reading your blog since like 4 months from now, and I really must say: your tutorials are very good, they has helped me in many of my works… Well, thank you very much man. I really admire your work.” ~ Leonardo
★★★★★ “Words can’t express how grateful I am for the work and the articles you post, had some troubles with doing somethings but your articles as per usual hit the hammer right on the head. They are a great way for expanding upon later too!” ~ Jeremy Smith
Got comments?
At codeofaninja.com, we strive to provide our readers with accurate and helpful Display Instagram Feed on your website using PHP Your feedback is essential in helping us achieve this goal.
If you have encountered any issues with the code, have suggestions for improvement, or wish to provide praise, we welcome you to leave a comment below. Please be as descriptive as possible to address your concerns effectively and include any relevant error messages, screenshots, or test URLs.
We request that comments remain on-topic and relevant to the article above. If your question or comment pertains to a different topic, we recommend seeking assistance elsewhere.
Furthermore, we ask that you review our code of conduct before commenting to ensure that your feedback is constructive and respectful.
Thank you for taking the time to provide feedback and for supporting codeofaninja.com. Your contributions help us improve our tutorials and serve the developer community better.
Subscribe for FREE!
Improve your web development skills and stay ahead of the competition by subscribing to our tutorial series. Sign up for FREE and access exclusive, cutting-edge content delivered straight to your inbox.
Take advantage of the chance to elevate your skills and advance your web development career. Subscribe now.
Thank You!
We hope you've found our Display Instagram Feed on your website using PHP helpful and informative. We understand that learning new programming concepts can be challenging, but we're glad we could make it easier for you.
Thank you for choosing to learn with us and for supporting codeofaninja.com! Consider sharing this tutorial with your friends and colleagues who may also be interested in learning about Display Instagram Feed on your website using PHP
The more people know about our tutorials, the more we can help the developer community grow. Keep learning, keep coding, and keep growing as a developer. We can't wait to see what you'll create next!
https://i0.wp.com/www.codeofaninja.com/wp-content/uploads/2015/01/display-instagram-feed-website-1.jpg?fit=750%2C393&ssl=1393750Mike Dalisayhttps://www.codeofaninja.com/wp-content/uploads/2019/03/codeofaninja-with-text-3-1030x206.pngMike Dalisay2015-01-03 02:17:392023-01-25 02:17:31Display Instagram Feed on your website using PHP
Today, our tutorial will explore integrating Facebook page videos onto a website using PHP. With this solution, website visitors can easily access the videos you've invested time in creating, editing, and managing on your Facebook page.
Say goodbye to manually uploading videos to both Facebook and your website. Implement our code and have your Facebook videos automatically displayed on your website for your audience to enjoy.
This is a great way to increase engagement on your website and encourage your audience to follow your Facebook page.
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 on a webpage made in PHP. We will use a user interface powered by Bootstrap. See our step-by-step Bootstrap tutorial here if you’re not yet familiar with this excellent front-end framework.
Don’t want to code?
Before we continue coding, if you 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.
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:
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.
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
<?php
// set timezone for servers that requires it
date_default_timezone_set("America/Los_Angeles");
// 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.
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
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.
Today we have learned how to show your Facebook page videos on your website. Did you know that you can also display a Facebook page posts feed on your website?
Don't just take our word for it. See what our students have to say about our tutorials and source codes. We are proud to have helped many individuals and businesses to build their own applications. Here are a few of the testimonials from our satisfied students.
★★★★★ “Wow, I love you guys! The best web programming tutorial I’ve ever seen. So comprehensive, yet easy to follow. I love how you combine all necessary elements in such a neat structure.” ~ Olaug Nessa
★★★★★ “The fact that you’ve put it all together saves so much time and its worth buying the code. Makes me feel good supporting a developer like yourself. Keep up the good work!” ~ Dan Hudson
★★★★★ “Thanks for making these awesome tutorials! I bought your source codes. To be honest, it’s very readable code and helps me understand a lot of things and how it’s done in PHP. Thanks for that again.” ~ Michael Lammens
★★★★★ “Hey Mike, my name is Leonardo from Argentina. I’ve been reading your blog since like 4 months from now, and I really must say: your tutorials are very good, they has helped me in many of my works… Well, thank you very much man. I really admire your work.” ~ Leonardo
★★★★★ “Words can’t express how grateful I am for the work and the articles you post, had some troubles with doing somethings but your articles as per usual hit the hammer right on the head. They are a great way for expanding upon later too!” ~ Jeremy Smith
Got comments?
At codeofaninja.com, we strive to provide our readers with accurate and helpful Display Facebook Page Videos On Website Using PHP Your feedback is essential in helping us achieve this goal.
If you have encountered any issues with the code, have suggestions for improvement, or wish to provide praise, we welcome you to leave a comment below. Please be as descriptive as possible to address your concerns effectively and include any relevant error messages, screenshots, or test URLs.
We request that comments remain on-topic and relevant to the article above. If your question or comment pertains to a different topic, we recommend seeking assistance elsewhere.
Furthermore, we ask that you review our code of conduct before commenting to ensure that your feedback is constructive and respectful.
Thank you for taking the time to provide feedback and for supporting codeofaninja.com. Your contributions help us improve our tutorials and serve the developer community better.
Subscribe for FREE!
Improve your web development skills and stay ahead of the competition by subscribing to our tutorial series. Sign up for FREE and access exclusive, cutting-edge content delivered straight to your inbox.
Take advantage of the chance to elevate your skills and advance your web development career. Subscribe now.
Thank You!
We hope you've found our Display Facebook Page Videos On Website Using PHP helpful and informative. We understand that learning new programming concepts can be challenging, but we're glad we could make it easier for you.
Thank you for choosing to learn with us and for supporting codeofaninja.com! Consider sharing this tutorial with your friends and colleagues who may also be interested in learning about Display Facebook Page Videos On Website Using PHP
The more people know about our tutorials, the more we can help the developer community grow. Keep learning, keep coding, and keep growing as a developer. We can't wait to see what you'll create next!
https://i0.wp.com/www.codeofaninja.com/wp-content/uploads/2014/10/display-facebook-video-on-website-1-1.jpg?fit=750%2C393&ssl=1393750Mike Dalisayhttps://www.codeofaninja.com/wp-content/uploads/2019/03/codeofaninja-with-text-3-1030x206.pngMike Dalisay2014-10-22 16:12:112023-01-25 02:18:22Display Facebook Page Videos On Website Using PHP
Today, in this tutorial, we will show you how to display Facebook page posts on your website using PHP. Posts from your Facebook page are essential to keep your audience informed, engaged, and updated with your latest content.
However, if you're not showing those posts to your website visitors, you miss out on a valuable opportunity to connect with them.
Our code in this tutorial will allow you to automatically display your Facebook page posts on your website using PHP. The integration process is straightforward, and once it's done, you can create and edit your posts on Facebook, and any changes will also be reflected on your website.
This will save you time and effort, as you won't need to manually update your website whenever you create a new post.
Overview
Our code for today will get any posts like videos, statuses, or pictures from your Facebook page using Facebook Graph API. We will beautifully display these posts or contents on a webpage (assuming it is your website) with Bootstrap.
See our step-by-step Bootstrap tutorial if you’re not yet familiar with this awesome front-end framework. It is also responsive, so it’s one advantage for mobile devices.
Don't want to code?
Before we continue coding, if you 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 feed and embed it on your website in 3 minutes. The posts feed on your website will update automatically.
Follow this tutorial: Embed Facebook page posts feed on website. You can also embed other feeds, such as Facebook page events, photos, videos, and more. There’s a free plan that you can use if you don’t need the premium features of SociableKIT.
But if you like coding, continue with our tutorial below!
Code Output
It is essential to know where we are going. Once we finish the tutorial, we will achieve the output in the video below.
Enjoy the step-by-step tutorial below!
Create the index page
Create index.php file with basic HTML code
This index file will be loaded first and what we will see on the browser. Create index.php file. Put the following code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Display Facebook page posts on website</title>
<!-- CSS will be here -->
</head>
<body>
<!-- Facebook page posts will be here -->
<!-- JavaScript will be here -->
</body>
</html>
Include Bootstrap and custom CSS
Here we include Bootstrap CSS and our own custom CSS to make our page look good. Replace <!-- CSS will be here --> comment with the following code.
Include Bootstrap and Font Awesome JavaScript. Bootstrap JavaScript is required for Bootstrap to work better. We use Font Awesome for the likes and comments count icons. Replace <!-- JavaScript will be here --> comment with the following code.
Here's the body of our webpage. In this part, we will display the Facebook page posts. Replace <!-- Facebook page posts will be here --> comment with the following code.
<div class="container">
<div class='col-lg-12'>
<h1 class='page-header'>Display Facebook page posts on website</h1>
<?php include "facebook_page_posts.php"; ?>
</div>
</div>
Custom CSS
Create custom.css file
Create a custom.css file. This file was used inside the index.php file. Put the following code.
/* profile css will be here */
/* post css will be here */
/* other css will be here */
Profile CSS
The following CSS code is intended for profile information on the page. Replace /* profile css will be here */ comment with the following code.
This file will be used to be the central place where the Facebook page posts feed will be requested (from the Facebook Graph API), processed, and displayed. Create a facebook_page_posts.php file. This file was also used inside the index.php file. Put the following code.
<?php
include "functions.php";
// parameters will be here
// json link and contents will be here
// posts loop will be here
?>
Create functions.php
We have one function in this file. Its purpose is to convert a date and time value to a "time ago" format. For example 1 day ago, 2 hours ago, 1 month ago, etc. Create functions.php file. This file was used inside the facebook_page_posts.php file. Put the following code.
These variables contains the parameters needed to make a request to the Facebook graph API. Replace // parameters will be here comment with the following code.
You need to replace YOUR_PAGE_ID and YOUR_PAGE_ACCESS_TOKEN with your own. There are two ways to retrieve your page ID and token.
The first method is this: To get your Facebook page ID, follow this tutorial. To get your Facebook page access token, follow this tutorial. This method can be time-consuming.
We can do this process for you but there will be a service fee of $50. Also, you will need to make us an admin of your Facebook page. If you want to avail of this service, pay using this link. After the payment, you will receive further instructions from [email protected]
The second method this: We built and maintain a tool where you can easily retrieve your page ID and token. It costs $30. You can buy an access here. This method is faster and easier.
JSON link and contents
In this part, we will build the whole request link and get the response from the API. Replace // json link and contents will be here comment with the following code.
// build json link and get contents
$json_link = "https://graph.facebook.com/{$fb_page_id}/posts?fields={$fields}&limit={$limit}&access_token={$access_token}";
$json = file_get_contents($json_link);
$obj = json_decode($json, true);
$feed_item_count = count($obj['data']);
Loop through posts
Once we got the response or the data from the API, we will loop through it this way. Each loop contains a Facebook post from your page. Replace // posts loop will be here comment with the following code.
// loop throug posts
foreach($obj['data'] as $post){
include "extract_values.php";
include "display_values.php";
}
Extract values
Create extract_values.php file
Create extract_values.php file. This file was used inside facebook_page_posts.php file. Put the following code.
// post id, link, and page name will be here
// when it was posted will be here
// attachments will be here
// message and story will be here
// likes and comments count will be here
Extract post ID, link and page name
In this code, we will get the post ID and page name. We will also build the link to the original post on Facebook. Replace // post id, link, and page name will be here comment with the following code.
// post id, link, and page name
$id = isset($post['id']) ? $post['id'] : "";
$link = "https://www.facebook.com/{$id}";
$page_name = isset($post['from']['name']) ? $post['from']['name'] : "";
Extract post date
The following code retrieves the post date and time. We convert this value to a "time ago" value. Post date will look like this: 4 weeks ago. 3 days ago, 1 month ago, 2 years ago. We are using the time_elapsed_string() function from functions.php file in this part of the code. Replace // when it was posted will be here comment with the following code.
// when it was posted
$created_time = isset($post['created_time']) ? $post['created_time'] : "";
$converted_date_time = date( 'Y-m-d H:i:s', strtotime($created_time));
$ago_value = time_elapsed_string($converted_date_time);
Extract attachments
We will get the post attachments. Attachments contains the post type, image or thumbnail, post title, and description. These data makes a post look more informative. Replace // attachments will be here comment with the following code.
The $message variable contains the custom text entered by the user for the post. The $story variable contains values such as "added an even" or "updated their status". Replace // message and story will be here comment with the following code.
// message and story ("updated their status." or "added an event")
$message=isset($post['message']) ? $post['message'] : "";
$message=htmlspecialchars_decode(str_replace("\n", "<br>", $message));
$story = isset($post['story']) ? $post['story'] : "";
Extract likes and comments count
The likes and comments count are important signals of engagement. The following code is how we get these values. Replace // likes and comments count will be here comment with the following code.
This file was also used inside facebook_page_posts.php file. Create display_values.php file. Put the following code.
<?php
echo "<div class='item_box'>
<div class='row'>";
<!-- left side of the post will be here -->
<!-- right side of the post will be here -->
echo "</div>
<hr />
</div>";
Display profile photo, story, post date, and message
The following code will display the page's profile photo, page name, date posted, and message. All on the right side of the post. Replace <! -- left side of the post will be here --> comment with the following code.
The following code will display the attachment image, title, and description on the right side of the post. There is a link to the post on Facebook. It will also display the likes and comments count. Replace <! -- right side of the post will be here --> comment with the following code.
Don't just take our word for it. See what our students have to say about our tutorials and source codes. We are proud to have helped many individuals and businesses to build their own applications. Here are a few of the testimonials from our satisfied students.
★★★★★ “Wow, I love you guys! The best web programming tutorial I’ve ever seen. So comprehensive, yet easy to follow. I love how you combine all necessary elements in such a neat structure.” ~ Olaug Nessa
★★★★★ “The fact that you’ve put it all together saves so much time and its worth buying the code. Makes me feel good supporting a developer like yourself. Keep up the good work!” ~ Dan Hudson
★★★★★ “Thanks for making these awesome tutorials! I bought your source codes. To be honest, it’s very readable code and helps me understand a lot of things and how it’s done in PHP. Thanks for that again.” ~ Michael Lammens
★★★★★ “Hey Mike, my name is Leonardo from Argentina. I’ve been reading your blog since like 4 months from now, and I really must say: your tutorials are very good, they has helped me in many of my works… Well, thank you very much man. I really admire your work.” ~ Leonardo
★★★★★ “Words can’t express how grateful I am for the work and the articles you post, had some troubles with doing somethings but your articles as per usual hit the hammer right on the head. They are a great way for expanding upon later too!” ~ Jeremy Smith
Got comments?
At codeofaninja.com, we strive to provide our readers with accurate and helpful Display Facebook page posts feed on website using PHP Your feedback is essential in helping us achieve this goal.
If you have encountered any issues with the code, have suggestions for improvement, or wish to provide praise, we welcome you to leave a comment below. Please be as descriptive as possible to address your concerns effectively and include any relevant error messages, screenshots, or test URLs.
We request that comments remain on-topic and relevant to the article above. If your question or comment pertains to a different topic, we recommend seeking assistance elsewhere.
Furthermore, we ask that you review our code of conduct before commenting to ensure that your feedback is constructive and respectful.
Thank you for taking the time to provide feedback and for supporting codeofaninja.com. Your contributions help us improve our tutorials and serve the developer community better.
Subscribe for FREE!
Improve your web development skills and stay ahead of the competition by subscribing to our tutorial series. Sign up for FREE and access exclusive, cutting-edge content delivered straight to your inbox.
Take advantage of the chance to elevate your skills and advance your web development career. Subscribe now.
Thank You!
We hope you've found our Display Facebook page posts feed on website using PHP helpful and informative. We understand that learning new programming concepts can be challenging, but we're glad we could make it easier for you.
Thank you for choosing to learn with us and for supporting codeofaninja.com! Consider sharing this tutorial with your friends and colleagues who may also be interested in learning about Display Facebook page posts feed on website using PHP
The more people know about our tutorials, the more we can help the developer community grow. Keep learning, keep coding, and keep growing as a developer. We can't wait to see what you'll create next!
https://i0.wp.com/www.codeofaninja.com/wp-content/uploads/2014/10/display-facebook-feed-on-website.jpg?fit=750%2C393&ssl=1393750Mike Dalisayhttps://www.codeofaninja.com/wp-content/uploads/2019/03/codeofaninja-with-text-3-1030x206.pngMike Dalisay2014-10-01 23:46:062023-01-25 02:17:57Display Facebook page posts feed on website using PHP
After creating a Facebook page where we will pull our data, we have to create an app to get an appId and appSecret keys. Those keys are required to use the Facebook PHP SDK and do our queries like pulling Facebook photos, events, videos, and feeds. Here’s a step by step tutorial on how to get those keys.
Step 1
Here’s the link where you would start: create a Facebook app. On the pop up, specify your app name (the name of your website or app) and app namespace (used for your Facebook app URL e.g., http://apps.facebook.com/yournamespace)
Step 2
You’ll be asked to enter a security code to verify that you’re a human and not a bot or malware that creates random Facebook apps. After entering the text in the box, click the “Continue” button.
Step 3
Congrats! now you can copy your Facebook appId and appSecret. See the arrows below.
Step 4
Prepare your App ID and App Secret keys, we’ll use it to get your access token, here’s how:
Replace YOUR_APP_ID and YOUR_APP_SECRET with your own and run the link on the browser.
https://www.codeofaninja.com/wp-content/uploads/2019/03/codeofaninja-with-text-3-1030x206.png00Mike Dalisayhttps://www.codeofaninja.com/wp-content/uploads/2019/03/codeofaninja-with-text-3-1030x206.pngMike Dalisay2013-02-28 01:24:002021-12-02 02:55:11How To Get Facebook App ID and Secret Keys?
Welcome to the start of our Social Media API Tutorial Series! We will start with this tutorial about how to display Facebook page events on your website using PHP.
In today's digital age, social media plays a crucial role in connecting businesses with their customers. As a business owner, you understand the importance of keeping your website up-to-date with the latest information about your company, including upcoming events.
However, manually updating your website with events from your Facebook page can be time-consuming and tedious.
In this tutorial, we will explore a solution to this problem by demonstrating how to use the Facebook API and PHP to automatically display your Facebook page events on your website.
With the code provided, you will be able to seamlessly integrate your Facebook events into your website, ensuring that your audience is always up-to-date with the latest happenings at your business.
Say goodbye to manual updates and hello to a streamlined and efficient way of sharing your events with your fans, audience, and customers.
Overview
This code will get the list of events from your Facebook page. It will show data such as event image, name, time, description, etc. from your Facebook fan page without using any Facebook PHP SDK, just the Facebook Graph API!
We will display these event data on a webpage, assuming it is a website made with PHP. 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 events feed and embed it on your website in 3 minutes. The events feed on your website will update automatically.
Follow this tutorial: Embed Facebook page events on website. You can also use the Facebook group events solution if you use Facebook groups. There's a free plan that you can use if you don't need the premium features of SociableKIT.
But if you like coding, continue with our tutorial below!
Final output
We have to know where we are going. If we completed the tutorial below, we will achieve the following output in the video below.
Create the index page
Create index.php file
This page is what will be loaded on the browser. Create an index.php file. Put the following basic HTML code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Display Facebook page events on website</title>
<!-- CSS will be here -->
</head>
<body>
<!-- Container will be here -->
</body>
</html>
CSS code
We're going to use Bootstrap to make our page look good. We'll also put some custom CSS. Replace <!-- CSS will be here --> with the following code.
These divs have Bootstrap classes. It will contain our Facebook page events. Replace <!-- Container will be here --> with the following code.
<div class="container">
<div class='col-lg-12'>
<h1 class='page-header'>Display Facebook page events on website</h1>
<!-- PHP code will be here -->
</div>
</div>
PHP code
The code below gets the parameter from the URL about what to display. By default, it is "upcoming" events. The navigation.php file will help the user to select upcoming or past events.
The fb_page_events.php file will contain our request to the Facebook Graph API. Replace <!-- PHP code will be here --> with the following code.
<?php
$display = isset($_GET["display"]) ? $_GET["display"] : "upcoming";
include "navigation.php";
include "fb_page_events.php";
?>
Create navigation.php file
This file will show two tabs that will allow our users to select upcoming or past events. Create a navigation.php file and put the following code.
This file will contain the process of building a request to the Facebook Graph API. Create fb_page_events.php file. Put the following code.
<?php
// specify date range will be here
// unix timestamp format will be here
// request parameters will be here
// build the api request will be here
// sort to display upcoming events will be here
// looping through events will be here
?>
Specify date range
The code below identifies the "since" and "until" dates that will be used for the API request. For upcoming events, the "since" date is the date today and the "until" date is two years from today.
For past events, the "since" date is the date from two years ago and the "until" date is the date yesterday.
Replace <!-- specify date range will be here --> with the following code.
// specify date range
$year_range = 2;
if($display=="upcoming"){
// date range for upcoming events
$since_date = date('Y-m-d');
$until_date = date('Y-12-31', strtotime('+' . $year_range . ' years'));
}
else{
// date range for past events
$since_date = date('Y-01-01', strtotime('-' . $year_range . ' years'));
$until_date = date('Y-m-d', strtotime('-1 day'));
}
Convert to unix timestamp
Unix timestamp is required by the Facebook Graph API. We will convert the since and until dates using the code below. Replace <!-- unix timestamp format will be here --> with the following code.
// unix timestamp format
$since_unix_timestamp = strtotime($since_date);
$until_unix_timestamp = strtotime($until_date);
Specify request parameters
The variables below are needed to complete the parameters needed for the Facebook Graph API request. Replace <!-- request parameters will be here --> with the following code.
The code below completes the API request link and get the response using file_get_contents() function. We will also decode the response so we can easily retrieve the data. Replace <!-- build the api request will be here --> with the following code.
// build the api request
$json_link = "https://graph.facebook.com/{$api_version}/{$fb_page_id}/events/attending/?fields={$fields}&access_token={$access_token}&since={$since_unix_timestamp}&until={$until_unix_timestamp}";
$json = file_get_contents($json_link);
$obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);
// for those using PHP version older than 5.4, use this instead:
// $obj = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $json), true);
Sort to display upcoming events
Sorting is needed to properly display the upcoming events. The code below will let the upcoming events to be displayed from the date nearest to today up to the farthest date. Replace <!-- sort to display upcoming events will be here --> with the following code.
// sort to display upcoming events
if($display=="upcoming"){
function sortFunction($a,$b){
if ($a['start_time'] == $b['start_time']) return 0;
return strtotime($a['start_time']) - strtotime($b['start_time']);
}
usort($obj['data'],"sortFunction");
}
Loop through events
The code below will loop through each events returned from the Facebook Graph API. Replace <!-- looping through events will be here --> with the following code.
// looping through events
foreach($obj['data'] as $event){
include "extract_values.php";
include "display_values.php";
}
Extract and display events data
Create extract_values.php file
In this file, we will extract different types of event data. Create extract_values.php file. Put the following code.
<?php
// start date and time will be here
// basic info will be here
// location will be here
?>
Extract date and time
The code below will let us get the event's start date and time. Replace <!-- start date and time will be here --> with the following code.
// start date and time
$timezone=isset($event['timezone']) ? $event['timezone'] : "America/Los_Angeles";
date_default_timezone_set($timezone);
$start_date = date( 'l, F d, Y', strtotime($event['start_time']));
// in my case, I had to subtract 9 hours to sync the time set in facebook
$start_time = date('g:i a', strtotime($event['start_time']));
Extract basic information
The code below will let us get the event ID, name, description, and thumbnail. Replace <!-- basic info will be here --> with the following code.
Today we have learned how to show your Facebook page events on your website. Did you know that you can also display Facebook photo albums and photos on your website?
Don't just take our word for it. See what our students have to say about our tutorials and source codes. We are proud to have helped many individuals and businesses to build their own applications. Here are a few of the testimonials from our satisfied students.
★★★★★ “Wow, I love you guys! The best web programming tutorial I’ve ever seen. So comprehensive, yet easy to follow. I love how you combine all necessary elements in such a neat structure.” ~ Olaug Nessa
★★★★★ “The fact that you’ve put it all together saves so much time and its worth buying the code. Makes me feel good supporting a developer like yourself. Keep up the good work!” ~ Dan Hudson
★★★★★ “Thanks for making these awesome tutorials! I bought your source codes. To be honest, it’s very readable code and helps me understand a lot of things and how it’s done in PHP. Thanks for that again.” ~ Michael Lammens
★★★★★ “Hey Mike, my name is Leonardo from Argentina. I’ve been reading your blog since like 4 months from now, and I really must say: your tutorials are very good, they has helped me in many of my works… Well, thank you very much man. I really admire your work.” ~ Leonardo
★★★★★ “Words can’t express how grateful I am for the work and the articles you post, had some troubles with doing somethings but your articles as per usual hit the hammer right on the head. They are a great way for expanding upon later too!” ~ Jeremy Smith
Got comments?
At codeofaninja.com, we strive to provide our readers with accurate and helpful Display Facebook page events on website using PHP Your feedback is essential in helping us achieve this goal.
If you have encountered any issues with the code, have suggestions for improvement, or wish to provide praise, we welcome you to leave a comment below. Please be as descriptive as possible to address your concerns effectively and include any relevant error messages, screenshots, or test URLs.
We request that comments remain on-topic and relevant to the article above. If your question or comment pertains to a different topic, we recommend seeking assistance elsewhere.
Furthermore, we ask that you review our code of conduct before commenting to ensure that your feedback is constructive and respectful.
Thank you for taking the time to provide feedback and for supporting codeofaninja.com. Your contributions help us improve our tutorials and serve the developer community better.
Subscribe for FREE!
Improve your web development skills and stay ahead of the competition by subscribing to our tutorial series. Sign up for FREE and access exclusive, cutting-edge content delivered straight to your inbox.
Take advantage of the chance to elevate your skills and advance your web development career. Subscribe now.
Thank You!
We hope you've found our Display Facebook page events on website using PHP helpful and informative. We understand that learning new programming concepts can be challenging, but we're glad we could make it easier for you.
Thank you for choosing to learn with us and for supporting codeofaninja.com! Consider sharing this tutorial with your friends and colleagues who may also be interested in learning about Display Facebook page events on website using PHP
The more people know about our tutorials, the more we can help the developer community grow. Keep learning, keep coding, and keep growing as a developer. We can't wait to see what you'll create next!
https://i0.wp.com/www.codeofaninja.com/wp-content/uploads/2011/07/display-facebook-events-on-website-1.jpg?fit=750%2C393&ssl=1393750Mike Dalisayhttps://www.codeofaninja.com/wp-content/uploads/2019/03/codeofaninja-with-text-3-1030x206.pngMike Dalisay2011-07-08 23:56:002023-01-25 02:19:54Display Facebook page events on website using PHP
This tutorial will cover the steps to display Facebook page photo albums on your website using PHP. We'll show you how to easily integrate your Facebook page's photo albums into your website so your audience can view them without having to navigate away from your site.
By the end of this tutorial, you'll have a seamless way to showcase your Facebook photo albums to your website visitors, keeping them engaged and up-to-date with your latest content.
Source Code Overview
Today we’re going to do a code that:
1. Gets photo albums and photos of a Facebook fan page (using Facebook Graph API).
2. Display these photos to a webpage (assuming it is your website) beautifully with Bootstrap. It is also responsive so it's one advantage for mobile devices. If you're not yet familiar with this awesome front-end framework, see our step by step Bootstrap tutorial here.
3. Use Bootstrap Image Gallery extension to make an awesome image pop-up presentation. This extension is fully responsive and touch-enabled. Good for every mobile device!
Don't want to code?
By the way, if you realize you do not want to code and need more features, you can use a website plugin called SociableKIT.
You can easily customize the look and feel of your Facebook page photo albums and embed them on your website within a few clicks. Following this tutorial: Embed Facebook page photo albums on website. There's also an option to embed only one photo album on Facebook.
There's a free plan that you can use if you don't need the premium features of SociableKIT. But if you like coding, continue with our tutorial below!
Benefits
Use this code to enjoy the following benefits.
You save server disk space because the photos don't reside in your hosting provider.
You got an instant photo manager which Facebook photos. It becomes awesome and new features are added frequently.
You save bandwidth since the photos shown on your website are loaded from Facebook’s servers.
Please add your comment if you know other advantages.
Get your page access token
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.
Loop through the retrieved content. Put the following code under $album_count variable on step 2 above. It links to another PHP file called photos.php where the user can view the photos inside the album.
for($x=0; $x<$album_count; $x++){
$id = isset($obj['data'][$x]['id']) ? $obj['data'][$x]['id'] : "";
$name = isset($obj['data'][$x]['name']) ? $obj['data'][$x]['name'] : "";
$url_name=urlencode($name);
$description = isset($obj['data'][$x]['description']) ? $obj['data'][$x]['description'] : "";
$link = isset($obj['data'][$x]['link']) ? $obj['data'][$x]['link'] : "";
$cover_photo = isset($obj['data'][$x]['cover_photo']['id']) ? $obj['data'][$x]['cover_photo']['id'] : "";
// use this for older access tokens:
// $cover_photo = isset($obj['data'][$x]['cover_photo']) ? $obj['data'][$x]['cover_photo'] : "";
$count = isset($obj['data'][$x]['count']) ? $obj['data'][$x]['count'] : "";
// if you want to exclude an album, just add the name on the if statement
if(
$name!="Profile Pictures" &&
$name!="Cover Photos" &&
$name!="Timeline Photos"
){
$show_pictures_link = "photos.php?album_id={$id}&album_name={$name}";
echo "<div class='col-md-4'>";
echo "<a href='{$show_pictures_link}'>";
echo "<img class='img-responsive' src='https://graph.facebook.com/v2.3/{$cover_photo}/picture?access_token={$access_token}' alt=''>";
echo "</a>";
echo "<h3>";
echo "<a href='{$show_pictures_link}'>{$name}</a>";
echo "</h3>";
$count_text="Photo";
if($count>1){ $count_text="Photos"; }
echo "<p>";
echo "<div style='color:#888;'>{$count} {$count_text} / <a href='{$link}' target='_blank'>View on Facebook</a></div>";
echo $description;
echo "</p>";
echo "</div>";
}
}
Create photos.php with GET request
Create photos.php with the following PHP code the retrieves value from a GET request. We'll get the album ID and Name that can be used to the page title.
<?php
$album_id = isset($_GET['album_id']) ? $_GET['album_id'] : die('Album ID not specified.');
$album_name = isset($_GET['album_name']) ? $_GET['album_name'] : die('Album name not specified.');
$page_title = "{$album_name} Photos";
?>
Basic HTML Code for photos.php
Under the code on step 4 above, put the following basic HTML code.
Today we have learned how to show your Facebook photo albums and photos on your website. Did you know that you can also display Facebook videos on your website?
Don't just take our word for it. See what our students have to say about our tutorials and source codes. We are proud to have helped many individuals and businesses to build their own applications. Here are a few of the testimonials from our satisfied students.
★★★★★ “Wow, I love you guys! The best web programming tutorial I’ve ever seen. So comprehensive, yet easy to follow. I love how you combine all necessary elements in such a neat structure.” ~ Olaug Nessa
★★★★★ “The fact that you’ve put it all together saves so much time and its worth buying the code. Makes me feel good supporting a developer like yourself. Keep up the good work!” ~ Dan Hudson
★★★★★ “Thanks for making these awesome tutorials! I bought your source codes. To be honest, it’s very readable code and helps me understand a lot of things and how it’s done in PHP. Thanks for that again.” ~ Michael Lammens
★★★★★ “Hey Mike, my name is Leonardo from Argentina. I’ve been reading your blog since like 4 months from now, and I really must say: your tutorials are very good, they has helped me in many of my works… Well, thank you very much man. I really admire your work.” ~ Leonardo
★★★★★ “Words can’t express how grateful I am for the work and the articles you post, had some troubles with doing somethings but your articles as per usual hit the hammer right on the head. They are a great way for expanding upon later too!” ~ Jeremy Smith
Got comments?
At codeofaninja.com, we strive to provide our readers with accurate and helpful How to display Facebook page photo albums on website using PHP? Your feedback is essential in helping us achieve this goal.
If you have encountered any issues with the code, have suggestions for improvement, or wish to provide praise, we welcome you to leave a comment below. Please be as descriptive as possible to address your concerns effectively and include any relevant error messages, screenshots, or test URLs.
We request that comments remain on-topic and relevant to the article above. If your question or comment pertains to a different topic, we recommend seeking assistance elsewhere.
Furthermore, we ask that you review our code of conduct before commenting to ensure that your feedback is constructive and respectful.
Thank you for taking the time to provide feedback and for supporting codeofaninja.com. Your contributions help us improve our tutorials and serve the developer community better.
Subscribe for FREE!
Improve your web development skills and stay ahead of the competition by subscribing to our tutorial series. Sign up for FREE and access exclusive, cutting-edge content delivered straight to your inbox.
Take advantage of the chance to elevate your skills and advance your web development career. Subscribe now.
Thank You!
We hope you've found our How to display Facebook page photo albums on website using PHP? helpful and informative. We understand that learning new programming concepts can be challenging, but we're glad we could make it easier for you.
Thank you for choosing to learn with us and for supporting codeofaninja.com! Consider sharing this tutorial with your friends and colleagues who may also be interested in learning about How to display Facebook page photo albums on website using PHP?
The more people know about our tutorials, the more we can help the developer community grow. Keep learning, keep coding, and keep growing as a developer. We can't wait to see what you'll create next!
https://i0.wp.com/www.codeofaninja.com/wp-content/uploads/2011/06/display-facebook-photos-on-website-1-1.jpg?fit=750%2C393&ssl=1393750Mike Dalisayhttps://www.codeofaninja.com/wp-content/uploads/2019/03/codeofaninja-with-text-3-1030x206.pngMike Dalisay2011-06-13 01:33:002023-01-25 02:20:34How to display Facebook page photo albums on website using PHP?