Display Facebook page posts feed on website using PHP

Previously, we learned how to display Facebook page videos on your 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.

<!-- 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>"; 

Source code or SociableKIT?

You can choose whether to download our source code or use the SociableKIT Facebook page events widget.

FEATURESCodeSociableKIT
Do it once: post on your Facebook page and automatically show it on your websiteโœ”โœ”
Save time studying and coding these features on your websiteโœ”โœ”
Automatically show the type of post. It can be status, link, video, etc.โœ”โœ”
Posts are linked to your Facebook page. Engage your visitors to your Facebook page.โœ”โœ”
The status post will have a โ€œView On Facebookโ€ linkโœ”โœ”
Posts will show the link thumbnail, title, and descriptionโœ”โœ”
Shows posted photoโœ”โœ”
Display the number of likesโœ”โœ”
Display the number of commentsโœ”โœ”
Responsive layout (great for mobile devices!)โœ”โœ”
Show โ€œtime agoโ€ of postsโœ”โœ”
Show like and comment iconsโœ”โœ”
No coding requiredโœ”
Works with any website builders like WordPress, Squarespace, or Wixโœ”
Customize colors, font, and moreโœ”
Priority chat and email supportโœ”
Lifetime support and system updatesโœ”
No need to worry about Facebook API updatesโœ”
Use the buttons below. โ†“CodeSociableKIT

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 an Instagram feed on website using PHP?

[adinserter block=”3″]


Comments

90 responses to “Display Facebook page posts feed on website using PHP”

  1. Thanks for this! Do you have to be a manager of the facebook page you want to display on your site?

    1. ninjazhai Avatar
      ninjazhai

      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!

  2. 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 ?

    1. ninjazhai Avatar
      ninjazhai

      Hey @omerosen,

      1. Yeah steps 5-7 is inside step 3 too.
      2. Yes again, under

      1. But if you just put it after you will get just text and no function. Or am I missing something here?

  3. 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.

    1. ninjazhai Avatar
      ninjazhai

      @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.

  4. 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

    1. your solution is add this line after ‘ <?php ':

      error_reporting(0);

      – View more: http://php.net/manual/en/function.error-reporting.php

  5. ninjazhai Avatar
    ninjazhai

    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.

  6. I have the same problem, do you fix it?

    1. ninjazhai Avatar
      ninjazhai

      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’] : “”;

      1. 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. ๐Ÿ™‚

  7. Martin Pfeiffer Avatar
    Martin Pfeiffer

    Step 8 is missing the open and close tag for PHP, so just add ” on the end of it, without the ‘ .

  8. Martin Pfeiffer Avatar
    Martin Pfeiffer

    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

    1. ninjazhai Avatar
      ninjazhai

      Hello @disqus_sTVjGfq9ri, I’m gonna add that feature in the future update of this code, thanks a lot for you suggestion!

  9. Freddy Morรกn Jr. Avatar
    Freddy Morรกn Jr.

    ยกLike a Boss! … ยกyou’re awesome! … ยกthanks a lot! ๐Ÿ˜€

    1. ninjazhai Avatar
      ninjazhai

      Hello there @freddynic159, thanks for visiting and glad you liked our tutorial!

  10. hi i can only get one output?
    i followed the tutorial step by step, and the limit is set to 5?

  11. Freddy Morรกn Jr. Avatar
    Freddy Morรกn Jr.

    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 “”;

    }

  12. Aykun Cetinkaya Avatar
    Aykun Cetinkaya

    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 ?

    1. 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.

  13. Aykun Cetinkaya Avatar
    Aykun Cetinkaya

    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.

    1. Thank you @aykuncetinkaya! I’m glad to help you!

  14. Pankaj Lohia Avatar
    Pankaj Lohia

    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.

  15. Pankaj Lohia Avatar
    Pankaj Lohia

    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?

    1. 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!

      1. Pankaj Lohia Avatar
        Pankaj Lohia

        Hey. I have made the site live. It’s at the bottom of the page on http://www.shade6.com. Thanks

  16. Wannabe Dev Avatar
    Wannabe Dev

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

    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.

      1. Wannabe Dev Avatar
        Wannabe Dev

        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. ๐Ÿ™

        1. Would you echo your $json_link and post it here?

          1. Wannabe Dev Avatar
            Wannabe Dev

            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.

          2. 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.

      2. Wannabe Dev Avatar
        Wannabe Dev

        By checking the source code (via browser) I noticed that the entire php code is missing. :

        1. @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.

  17. Antifaith Avatar
    Antifaith

    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’];

    1. 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?

      1. Antifaith Avatar
        Antifaith

        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

  18. andresclua Avatar
    andresclua

    hi there!
    Is this possible to mix this feed with other social networks?

    btw this is really good coding.

    1. 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!

  19. Wilma Biemold Avatar
    Wilma Biemold

    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?

    1. 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?

      1. Paula Laneri Avatar
        Paula Laneri

        @ninjazhai I have the same problem ๐Ÿ™

        1. @paulalaneri, would you tell us your test URL? Make sure you are using PHP 5.4+, JSON support and url_allow_fopen is enabled.

  20. 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

    1. 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.

  21. Heya, can I make this work with a Personal page, rather than a Fan page?

    1. Hello @disqus_lJum9KOKyY, you can use the script for Fan pages only.

  22. Yanek Yuk Avatar
    Yanek Yuk

    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

    1. Yanek Yuk Avatar
      Yanek Yuk

      I see now that your examples are suffering from the same problem also.

      1. 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?

        1. Yanek Yuk Avatar
          Yanek Yuk

          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.

          1. Would you share your Facebook page ID? Our demo is working, please see attached pic. Please send more details on my email [email protected]

          2. Yanek Yuk Avatar
            Yanek Yuk

            Nothing wrong the facebook ID or anything. It’s caused by my computer. I wonder why.

          3. Please let us know, if your found out the reason why it works that way in your computer, thanks!

          4. Yanek Yuk Avatar
            Yanek Yuk

            I haven’t found what causes it. I simply ignore it for now. If I ever fix it I will write it down here.

  23. Joshmar Steffens Avatar
    Joshmar Steffens

    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

  24. 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.

  25. 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!

    1. 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?

      1. Nope sorry, It is on a closed closed development environment. But the demo on this page behaves the same.

        1. 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)

  26. how did you get this working? where does this code go?

  27. 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}”;

    1. Hello @disqus_vBF12GgHe1 , thanks for sharing your solution! This will be useful for other people who wants the same feature. ๐Ÿ™‚

  28. Justin Webb Avatar
    Justin Webb

    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!

    1. 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.

  29. 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 ๐Ÿ™

    1. 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?

      1. 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/

        1. Thanks for sharing the link and I’m glad it works for you now Adrian!

  30. Gabriel Paquin Avatar
    Gabriel Paquin

    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

    1. 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.

  31. Colin Bradbury Avatar
    Colin Bradbury

    Fantastic script and great support. Great to see people sharing there scripts to help those of us just starting out to learn.

    1. Thanks for the kind words @colinbradbury ! Glad to help you make the script work on your site! ๐Ÿ™‚

  32. JamesB Avatar
    JamesB

    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!

  33. JamesB Avatar
    JamesB

    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?

    1. Hi @disqus_CstA6xP8PJ , would you tell us the Facebook page you’re trying to access? We’ll try to replicate the issue.

      1. 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.

        1. Your Facebook page is not publicly available. Please make it public.

          1. Good point, well made! Thanks!

  34. Satyam Avatar
    Satyam

    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!

    1. Hi @disqus_kCDSjdDJQ1 , make sure your server has JSON and allow_url_fopen turned on or enabled.

      1. Satyam Avatar
        Satyam

        my server has json! and i have no clue how to enable allow_url_fopen? can you help me out with this please!

        1. 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.

  35. You’re welcome @disqus_kCDSjdDJQ1!

  36. adrian Avatar
    adrian

    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

    1. Hi @disqus_HnG6KNYJZM you can put an ‘if condition’ to change a text if the type of post is an event.

  37. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *