In this tutorial, I will show you how to display Facebook page posts on website using PHP.
Posts from your Facebook page are not shown to your website visitors. You spend a lot of time creating, editing, and managing your posts. But your fans, audience, and customers from your website still do not see your Facebook posts.
Our code in this tutorial will allow you to automatically display your Facebook page posts on your website using PHP. Create and edit your posts on Facebook and any changes will also be reflected on your website.
Contents
Overview
Our code for today will get any type of post like videos, statuses, or pictures from your Facebook page using Facebook Graph API.
We will display these posts or contents to a webpage (assuming it is your website) beautifully with Bootstrap.
If you’re not yet familiar with this awesome front-end framework, see our step-by-step Bootstrap tutorial here. It is also responsive so it’s one advantage for mobile devices.
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 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 on website. You can also embed other types of 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 important to know where we are going. Once we finished 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.
<!-- CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="custom.css" media="screen">
Include JavaScript
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.
<!-- JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src="https://kit.fontawesome.com/dd3a1aa24e.js" crossorigin="anonymous"></script>
Put code for Facebook page posts
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.
.profile-info{
overflow:hidden;
}
.profile-photo{
float:left;
margin:0 .5em 0 0;
}
.profile-photo img{
width:40px; height:40px;
}
.profile-name{
float:left;
width:85%;
}
.profile-message{
margin:1em 0;
}
Post CSS
The following CSS code is for post information on the page. Replace /* post css will be here */ comment with the following code.
.post-link{
text-decoration:none;
}
.post-content{
background: #f6f7f9; overflow:hidden;
}
.post-content img{
width:100%;
}
.post-status{
margin:.5em; font-weight:bold;
}
.post-picture{
width:25%; float:left;
}
.post-info{
width:70%; float:left; margin:.5em;
}
.post-info-name{
font-weight:bold;
}
.post-info-description{
color:#999;
}
Other CSS
These are other CSS codes used to make our web page look good. Replace /* other css will be here */ comment with the following code.
.page-header{
margin:50px 0;
}
.time-ago{
color:#999;
}
.like-count-summary{
margin-top:10px;
}
Display Facebook page posts
Create facebook_page_posts.php file
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.
<?php
// 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 {
unset($string[$k]);
}
}
if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
}
?>
Parameters
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.
// prepare parameters
$fb_page_id = "YOUR_PAGE_ID";
$api_version = "v11.0";
$profile_photo_src = "https://graph.facebook.com/{$api_version}/{$fb_page_id}/picture?type=square";
$access_token = "YOUR_PAGE_ACCESS_TOKEN";
$fields = "id,attachments,message,picture,icon,created_time,from,story,likes.limit(0).summary(true),comments.limit(0).summary(true)";
$limit = 30;
Specify your Facebook page ID and token
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.
// attachments
$att_type = "";
$att_title = "";
$att_description = "";
$att_image = "";
if(isset($post['attachments'])){
$att_type = isset($post['attachments']['data'][0]['type'])
? $post['attachments']['data'][0]['type'] : "";
$att_title = isset($post['attachments']['data'][0]['title'])
? $post['attachments']['data'][0]['title'] : "";
$att_description = isset($post['attachments']['data'][0]['description'])
? $post['attachments']['data'][0]['description'] : "";
$att_image = isset($post['attachments']['data'][0]['media']['image']['src'])
? $post['attachments']['data'][0]['media']['image']['src'] : "";
}
Extract message and story
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.
// likes and comments count
$likes_count=isset($post['likes']['summary']['total_count'])
? $post['likes']['summary']['total_count'] : 0;
$comments_count=isset($post['comments']['summary']['total_count'])
? $post['comments']['summary']['total_count'] : 0;
Display values
Create display_values.php file
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.
// left side
echo "<div class='col-md-4'>
<div class='profile-info'>
<div class='profile-photo'>
<a href='https://fb.com/{$fb_page_id}' target='_blank'>
<img src='{$profile_photo_src}' />
</a>
</div>
<div class='profile-name'>
<div>";
echo !empty($story) ? $story : $page_name;
echo "</div>
<div class='time-ago'>{$ago_value}</div>
</div>
</div>
<p class='profile-message'>
{$message}
</p>
</div>";
Display attachments, likes, and comments count
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.
// right side
echo "<div class='col-md-8'>
<a href='{$link}' target='_blank' class='post-link'>
<div class='post-content'>";
if($att_image){
echo "<div class='post-picture'>
<img src='{$att_image}' />
</div>";
}
else{
echo "<div class='post-status'>
View on Facebook
</div>";
}
// if there's an attached title and description
if($att_title && $att_description){
echo "<div class='post-info'>
<div class='post-info-name'>{$att_title}</div>
<div class='post-info-description'>{$att_description}</div>
</div>";
}
echo "</div>
</a>
<div class='like-count-summary'>
<div style='float:left; margin:0 .6em 0 0;'>
<i class='far fa-thumbs-up'></i> {$likes_count}
</div>
<div style='float:left;'>
<i class='far fa-comments'></i> {$comments_count}
</div>
</div>
</div>";
What People Say About This Code?
I’m so glad that other people are delighted by this code, here are some of them!
★★★★★ “This guy is the best. There was a small issue and he helped right away. I recommend this script to everybody. Instead of wasting time by copy-pasting, just purchased the package and saved a lot of time also it came with many ajax features.” ~ Aykun
★★★★★ “BIG THANKS! I’ve been searching and messing around with SDK, Composer, FB APIs… to achieve to place feeds in my FB page to appear on my website without any luck until now.” ~ Hip
★★★★★ “Hi there Mr. Ninja, thanks for that guide and your effort. It is working great after I understood how to use it. :)” ~ Martin Pfeiffer
★★★★★ “Like a boss! You’re awesome! Thanks a lot!” ~ Freddy Moran Jr.
★★★★★ “Thanks for the script!” ~ Omer Rosenbaum
★★★★★ “Thanks a lot. Amazing support. Let me know if there is anywhere that I can write a review.” ~ A. Cetinkaya
Download Source Code
You can get the source code 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 with 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.
FEATURES | BASIC |
Do it once: post on your Facebook page and automatically show it on your website | Yes |
Save time studying and coding these features on your website | Yes |
Automatically show type of post, it can be status, link, video, etc. | Yes |
Posts are linked to your Facebook page. Engage your visitors to your Facebook page. | Yes |
Status post will have “View On Facebook” link | Yes |
Posts will show the link thumbnail, title, and description | Yes |
Shows posted photo | Yes |
Display number of likes | Yes |
Display number of comments | Yes |
Bootstrap UI enabled | Yes |
Responsive layout (great for mobile devices!) | Yes |
Show “time ago” of posts | Yes |
Show like and comment icons | Yes |
Free email support for 3 months. | Yes |
Free source code updates. | Yes |
$50 – Download now |
Do you need more reasons to download the source code?
MORE REASONS TO DOWNLOAD THE CODE | |
One-time payment. No need to buy a subscription. | Yes |
Buy only once, use on up to 5 websites and Facebook pages! | Yes |
No different kind of licenses. | Yes |
No many different pricing schemes. | Yes |
No monthly or yearly fees. | Yes |
No need to rely on another website to render Facebook timeline feeds | Yes |
No need for codes from other websites. | Yes |
Familiarize yourself with the Facebook Graph API. | Yes |
Completely customizable. | Yes |
Need help and support? email [email protected]
Thank you for supporting our projects here at codeofaninja.com!
What’s Next?
Today we have learned how to show your Facebook page posts on your website. Did you know that you can also display Instagram feed on your website?
Let us go to the next tutorial: How to display Facebook page events on website using PHP?
Related Tutorials
We have more tutorials related to social media APIs. Click here.
Some Notes
Found An Issue?
If you found a problem with this code, please send us an email. Before you send an email, please read our our code of conduct. Our team's email address is [email protected]
Please be descriptive about your issue. Please provide the error messages, screenshots (or screen recording) and your test URL. Thanks!
Subscribe to CodeOfaNinja
Receive valuable web development tutorials to your email. Subscribe now for FREE!
Thank You!
Thanks for visiting our tutorial on how to display Facebook page posts on the website using PHP and Facebook Graph API!
Hi @disqus_p6iJ2hWqX9, your statement is accurate. It is truly frustrating. Our code above will work but it needs an approve app and correct page access tokens.
Is there a way to change a to an for when you shared events… it says “user has shared a….” but for event should be an
Hi @disqus_HnG6KNYJZM you can put an ‘if condition’ to change a text if the type of post is an event.
You’re welcome @disqus_kCDSjdDJQ1!
This code is working fine on my xampp local server, but as soon as i run it on my php live server, {post_id} is not tracked down. Can you please help me, its very urgent!
Hi @disqus_kCDSjdDJQ1 , make sure your server has JSON and allow_url_fopen turned on or enabled.
my server has json! and i have no clue how to enable allow_url_fopen? can you help me out with this please!
You can ask your web hosting provider to enable it for you.
To verify it was enabled, try to create a new “info.php” file, inside this file put:
phpinfo();
Make sure it is between php tags. Run that info.php file and post link here.
Looks like a really good script, however I’m having problems getting anything out of Facebook and I wonder if you could help.
I’m created an App, and I’m using the correct access token (generated as your example) and the correct page ID, and yet all I get from the FB api is an error message :
“Unsupported get request. Object with ID ‘[PAGE ID]’ does not exist, cannot be loaded due to missing permissions, or does not support this operation. ”
Do I have to set any permission within the FB page or within the FB app that haven’t been mentioned within the tutorial?
Hi @disqus_CstA6xP8PJ , would you tell us the Facebook page you’re trying to access? We’ll try to replicate the issue.
HI- I’m trying to get the first few posts from https://www.facebook.com/FlashTours/?fref=ts to appear. I’ve logged in as the owner of the page, activated the developer account, setup an app and used all the tokens and ids as shown in your example. Not sure what I’ve mssed.
Your Facebook page is not publicly available. Please make it public.
Good point, well made! Thanks!
Great script, however I can’t seem to get any data to come out of the Graph API. I imagine I’ve not setup something correctly but all I get is the error below:
“Object with ID ‘[XXXXCORRECT-FB-OBJ-IDXXX]’ does not exist, cannot be loaded due to missing permissions, or does not support this operation.”
Do I need to set permissions up in the FB app configuration?
I’ve looked around a lot, but can’t see anything that makes it obvious.
Any help greatly appreciated!
Fantastic script and great support. Great to see people sharing there scripts to help those of us just starting out to learn.
Thanks for the kind words @colinbradbury ! Glad to help you make the script work on your site! :)
I like your website and your tutorials are very useful. Recently, I learn how to get the tweeter’s feed and also the instagram’s one because of you.
But with the facebook’s feed, strangely when I try to get the JSON content, i have that error :
(#100) Tried accessing nonexisting field (feed) on node type (Application)
Do you know why?
Thanks to answering!
-Gab
Hello @disqus_xMUoh9Zb9r , thanks for the kind words! Glad your tutorials helped you on your projects.
About your question, you can try /posts/ instead, read this for more info https://developers.facebook.com/docs/graph-api/reference/v2.7/page/feed
You may want to give us your test URL so we can investigate more about the issue. We are unable to replicate it. As you can see, our demos are working.
My website doesn’t seem to update the latest news. has the same posts. The time updated doesn’t seem to change either. Weird thing is if i re upload the file it will update but it seems only in chrome. One the browsers it doesn’t update on if there is a video it says wrong mime type.. worked when i frist did it :(
Hello Adrian, thanks for reaching out! Would you link us to your test URL and Facebook page so we can investigate more about this issue?
I think I found out. The cms i was using had a cache option in it’s config that was not allowing new posts to update.
Now just got to sort out why facebook link has changed!
http://www.brandedbyfire.rocks/
Thanks for sharing the link and I’m glad it works for you now Adrian!
Hi – I’m curious if it is possible with this code (or a few simple changes) to only pull certain posts from the page. For example, so posts are hashtaged “Marketing” and some are hashtaged “Design” and I only want to pull the ones that are hashtaged “Marketing” – BTW – YOU ROCK!
Hello @disqus_MM75W44AQA , thanks for the kind words! About your question, unfortunately our code cannot pull posts by hashtags. I remember it can be done in api version 1.0 before but this feature was gone in 2.0 onwards.
So after six hours I finally solved the problem with other people showing up in your page feed. Simply replace feed with posts:
“https://graph.facebook.com/{$fb_page_id}/feed?access_token={$access_token}&fields={$fields}&limit={$limit}”;
“https://graph.facebook.com/{$fb_page_id}/posts?access_token={$access_token}&fields={$fields}&limit={$limit}”;
Hello @disqus_vBF12GgHe1 , thanks for sharing your solution! This will be useful for other people who wants the same feature. :)
how did you get this working? where does this code go?
On my website and your demo the images are nog loading in Firefox. It works perfect in Chrome and Safari. Any idea how to solve this?
Update: Changed Firefox history setting from ‘Never remember history’ to ‘Remember history’ and now it works!
Hello @disqus_okn1WG3kdy, thanks for reporting the issue and sharing your solution! Would you share your website so we can investigate more about the issue?
Nope sorry, It is on a closed closed development environment. But the demo on this page behaves the same.
Alright, we understand. If it helps, we tested the demo and we are unable to replicate the issue here at our end (with the latest version of Firefox)
Hello @joshmarsteffens, my apologies for the late reply, you should send me an email at [email protected]. Anyway, about your concern, would you tell us your Facebook page link? We will try to replicate your issue and come up with a solution. Please email more details via email.
Hello,
I have a fiew questions reguarding the Basic source code that i bought from you (witch by the way is AWESOME exactly what i was looking for for a long time.)
but i have some error’s:
when i just run your pack without any changes it tells me
Notice: Undefined index: description in C:xampphtdocstestsfacebook_postsindex.php on line 155
Notice: Undefined index: object_id in C:xampphtdocstestsfacebook_postsindex.php on line 167
Notice: Undefined index: comments in C:xampphtdocstestsfacebook_postsindex.php on line 233
and some more undefined indexes when im changing the page id to the one i want to use.
next to that the images from the like button and the comments button misses (I checked the link and it returns an emputy page)
Thanks for all the coding its amazing work!
-Joshmar
Great tutorial. But I have the problem of missing images also.
The weird thing is there’s nothing wrong with the code. For instrance I can put ” “https://graph.facebook.com/{$fb_page_id}/picture?type=square” link into the adress bar while changing the “fb_page_id” and I can get to the square profile picture whether I am logged in or not, it doesn’t matter. But when the webpage I am using this on tries to do it, it doesn’t work. I am guessing it’s because of a non-granted permission. I hope someone has a solution for this.
Thanks in advance.
-Yanek
I see now that your examples are suffering from the same problem also.
Hello @yanekyuk, we are unable to replicate the error you described, our demo links above works fine. Would you send your test URL or a screenshot?
I think the problem is about me. As you can see, external links work just fine. But the ones that are coming from facebook server. Check the image I’ve uploaded.
Would you share your Facebook page ID? Our demo is working, please see attached pic. Please send more details on my email [email protected]
Nothing wrong the facebook ID or anything. It’s caused by my computer. I wonder why.
Please let us know, if your found out the reason why it works that way in your computer, thanks!
I haven’t found what causes it. I simply ignore it for now. If I ever fix it I will write it down here.
Heya, can I make this work with a Personal page, rather than a Fan page?
Hello @disqus_lJum9KOKyY, you can use the script for Fan pages only.
This code is amazing. I’m looking for use Facebook API without SDK, then i found this code. but, i have some issue about API. I had trying to open this API link (
https://graph.facebook.com/141897xxxx/feed?access_token=150970xxxxxxxx&fields=id,message,picture,link,name,description,type,icon,created_time,from,object_id&limit=5) in my browser to get some feed in my facebook account, but it only look like this
{
“data”: [
]
}
The “data” shouldn’t empty. Is there any wrong with that link? sorry for bad english
Hello @disqus_wHiZMCQZ8T, thanks for the kind words! About your concern, you cannot get Facebook feed using your personal FB account, this script works only with Facebook pages.
Hello! Great tutorial! I only have one little problem and that is I only get one post: http://www.loeq.nl/facebook.php. The facebookpage I’m referring: https://www.facebook.com/loeqmedia . What am I missing here?
Hello @wibi25, thanks! About your issue, your FB page works well with our script, here’s a live demo https://www.codeofaninja.com/demos/display-facebook-timeline-feeds-pro/index.php?fb_page_id=143433252414453
Would you show us your code?
@ninjazhai I have the same problem :(
@paulalaneri, would you tell us your test URL? Make sure you are using PHP 5.4+, JSON support and url_allow_fopen is enabled.
hi there!
Is this possible to mix this feed with other social networks?
btw this is really good coding.
Hello @andresclua, the code above is for Facebook only. We are working on a twitter feed script! I’m glad you found this a good coding, thanks!
Hi, having an issue with the feed displaying content from another user posting on the page, how could I limit the feed to match only the authors ID from $fb_page_id?
$obj[‘data’][$x][‘from’][‘id’];
Hello @antifaith, thanks for letting us know about this issue, we’re working on it. By the way, would you link us to the FB page you’re trying to use this script with?
https://www.facebook.com/Watersmeethotel1?fref=ts
$found_post = false;
for($x=0; $x<$feed_item_count; $x++){
$fb_author_id = $obj['data'][$x]['from']['id'];
if ($fb_author_id == $fb_page_id) {
$found_post = true;
break;
}
}
if (! $found_post) {
echo "";
return;
}
Fixed it, though there was then an issue when they posted a link to something that bought up a thumbnail, and now when they've posted a facebook video, there's no fallbacks for not being able to deal with this data
I’m sorry to bother you. I’m new to coding so I thought of asking before diving into this adventure.
The first part of step 3 seems vague to me and I can’t understand how to “create an app” as you suggest.
The URL you show leads me to this message:
{
“error”: {
“message”: “An unknown error has occurred.”,
“type”: “OAuthException”,
“code”: 1
}
}
Hello @Wannabe Dev, sorry I forgot to include a link, here’s how you can create an app to get the needed FB IDs or tokens https://www.codeofaninja.com/2013/02/facebook-appid-and-appsecret.html ~ the tutorial might be outdated but you will get the idea.
Thanks. I followed the other article’s guide but now i’m stuck again.
I followed all your steps and the only thing that i happen to see in my index.php is the page title (I’m testing this in localhost with MAMP).
I copy pasted everything (and changed the id and the access token) in this page and I can’t understand what’s wrong. :(
Would you echo your $json_link and post it here?
Ok. I just accomplished it by trying it on a NetBeans project. By the way, how can i test it locally? I’m trying to put the localhost in the app domain but it seems that it doesn’t work.
I made this script in localhost, I was using WAMP. I think it should also work for you given the right requirements. Recommended is PHP 5.4+ and JSON extension is enabled.
By checking the source code (via browser) I noticed that the entire php code is missing. :
@Wannabe Dev, you won’t see the PHP source code when you try to ‘view source’ in the browser because it is a server side script.
Hey, thank you for the code. It works fine except that I am unable to get pictures exctacted from the links i have posted on the fb page. The images are not displaying on the webpage except for one post which was taken from fb newsroom. How can i get the images to display? please help?
Hello @pankajlohia, what FB page are you trying to test? Do you see any error message? Best if you can provide your test URL… thanks!
Hey. I have made the site live. It’s at the bottom of the page on http://www.shade6.com. Thanks
hello. Thanks for the code. works fine except that it wont display any pictures except pictures of posts taken from fb newsroom itself. what do i do for it to display the pictures of posts? The posts are hyperlinks and fb populates the picture by itself from those links.
This guy is the best. There was a small issue and he me helped right away. I recommend this script to everybody. Instead of wasting time by copy pasting, just purchased the package and saved a lot of time also it came with many ajax features.
Thank you @aykuncetinkaya! I’m glad to help you!
I just purchased the plugin but I doubles up every post. I Just checked the demo and it looks the same. Is there a solution for this ?
Thanks for purchasing the code! It looks fine now, I think FB is having an API update. That’s why it doesn’t seem to work, but this rarely happens. I’ll send you an email.
This can be useful if you want to add an image in case of the type of publication was a video (for youtube only):
*add this after the line “if($type==”status”){…….}”.
else if($type==”video”){
$parse_vurl = parse_str(parse_url($link,PHP_URL_QUERY), $get_from_var);
$youtube_vid = $get_from_var[‘v’];
echo “”;
}
hi i can only get one output?
i followed the tutorial step by step, and the limit is set to 5?
¡Like a Boss! … ¡you’re awesome! … ¡thanks a lot! :D
Hello there @freddynic159, thanks for visiting and glad you liked our tutorial!
Hi there, Mr. Ninja.
Thanks for that guide and your effort. It is working great, after I understood how to use it ^^.
One question:
I’m grabbing the whole feed of a public Facebook timeline. There are some posts, who are just shared, so the original post is on another timeline.
Those are displayed as “XYZ shared a status” and its link “View on Facebook”.
Is there a way, to display the whole shared status in my feed?
Regards,
Tin
Hello @disqus_sTVjGfq9ri, I’m gonna add that feature in the future update of this code, thanks a lot for you suggestion!
Step 8 is missing the open and close tag for PHP, so just add ” on the end of it, without the ‘ .
I have the same problem, do you fix it?
Hello you guys, you can try to do it like this:
$picture_url = urldecode(isset($picture_url_arr[1]) ? $picture_url_arr[1] : “”);
$name = isset($obj[‘data’][$x][‘name’]) ? $obj[‘data’][$x][‘name’] : “”;
$description = isset($obj[‘data’][$x][‘description’]) ? $obj[‘data’][$x][‘description’] : “”;
It’s fix the notice messages, thank you. But now, I can only see one post. I have add $limit = 10 and only one post is printed. Any help is appreciated. :)
Sorry for the late reply, the Notice: Undefined means there’s no value on the variable you’re trying to access. You can try to use the isset() function to check if a variable has value.
Hi. First of all: BIG THANX
I’ve been searching and messing around with SDK, Composer, FB APIs,.. to achieve to place feeds in my FB page to appear on my website without any luck until now.
Now it does work but in debugg mode I still get the following error messages:
– Notice: Undefined offset: 1 in… ($picture_url = urldecode($picture_url_arr[1]);)
– Notice: Undefined index: name in… ($name = $obj[‘data’][$x][‘name’];)
– Notice: Undefined index: description in… ($description = $obj[‘data’][$x][‘description’];)
Am I doing anything wrong? Any clue?
T.I.A.,
hip
your solution is add this line after ‘ <?php ':
error_reporting(0);
– View more: http://php.net/manual/en/function.error-reporting.php
Will this keep on working? Or is it possible facebook has an API update and you have to update the code on your own website.
@disqus_5mevFn3QMc, as long as Facebook provides the API, I will keep updating this code based on that API. Usually, FB updates their API every few years only.
Hi,
Thanks for the script. A few questions regarding the script:
1. should steps 5-7 should be inside step 3’s
2. step 8 – did you mean under ?
Hey @omerosen,
1. Yeah steps 5-7 is inside step 3 too.
2. Yes again, under
But if you just put it after you will get just text and no function. Or am I missing something here?
Thanks for this! Do you have to be a manager of the facebook page you want to display on your site?
Hello @amosmos, no, you don’t have to be a manager of your FB page, it can display any FB page timeline feed as long as you have your own access token!