A Facebook page feed can be display on website using Facebook SDK. In this tutorial we will show you how to fetch all your Facebook page feed using graph API and with SDK. It is possible to get Facebook page public feed and you can display on site on any event. In this article you can see how to display custom Facebook feed with Graph API. When we try to get interact with facebook for our site we need to create a facebook application. The app you will create from facebook developer section will interact with website and response using graph API. For access of Graph API we must have Facebook SDK file source to include. To create facebook Application we have to follow some steps which are as follows. Table of Contents To Get Access Token follow the steps given belowLogin to facebook developer Page ID can be get as follows with few simple steps:Click on star icon on top left corner of facebook. <?php $page_id = 'YOUR PAGE ID'; $access_token = 'YOUR PAGE ACESS TOKEN'; //Get the data response in JSON $json_object = @file_get_contents('https://graph.facebook.com/' . $page_id . '/posts?access_token=' . $access_token); //Interpret data $fbfeeddata = json_decode($json_object); foreach ($fbfeeddata->data as $post ) { echo '<p><a href="' . $post->link . '">' . $post->story . '</a></p>'; echo '<p><img src="'.$post->picture.'">'.'<br>'.'<a href="' . $post->link . '">' . $post->message . '</a></p>'; echo '<p>' . $post->description . '</p>'; } ?> Alternate Approach:Either you can use above code or below alternate code to get Facebook feed. <?php include "src/facebook.php"; Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false; //convert text url into links. function make_links_to_text_url($text, $class='', $target='_blank'){ return preg_replace('!((http\:\/\/|ftp\:\/\/|https\:\/\/)|www\.)([-a-zA-Zа-яА-Я0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?!ism', '<a class="'.$class.'" href="//$3" target="'.$target.'">$1$3</a>', $text); } define("YOUR_APP_ID", 'Your app id here'); define("YOUR_APP_SECRET",'App Secret'); define("PAGE_ID",'Your Page ID'); $config = array( 'appId' => YOUR_APP_ID, 'secret' => YOUR_APP_SECRET, ); $api = new Facebook($config); $posts = $api->api("/".PAGE_ID."/posts?limit=10"); ?> <?php foreach ($posts['data'] as $post){ echo "<p>"; echo make_links_to_text_url($post['message']); echo make_links_to_text_url($post['story']); echo make_links_to_text_url($post['description']); echo "</p>"; } ?> Demo I just need a code sample that collects public posts from a facebook page to a PHP array. I've created an APP so I have the App ID/API Key and App Secret. For example, let's say that I want to get all the stackoverflow public posts from Facebook. I've found out that stackoverflow's facebook page id is '11239244970', but now, how do I get all their public posts?
asked Mar 24, 2013 at 20:11
You execute an HTTP GET to PAGE_ID/feed
https://developers.facebook.com/docs/reference/api/page/#feed in PHP it can be as basic as
or you can use the PHP SDK.
To get only the page's own posts and not the fans who like the page, use the answered Mar 24, 2013 at 20:18
phwdphwd 20k5 gold badges49 silver badges78 bronze badges 4 How can I connect Facebook with PHP?PHP - Facebook Login. Login With Facebook. Need to go https://developers.facebook.com/apps/ and click on add a new group button to make the app ID. Choose Website. ... . fbconfig. php file overview. ... . Login page Overview. Login page is used to login into FB. ... . Index. php. ... . Logout Facebook. Below code is used to logout facebook.. How can I get Facebook page reviews in PHP?$request = $fb->request('GET', '/'. $page_id. '/'); // Send the request to Graph try { $response = $fb->getClient()->sendRequest($request); } catch(Facebook\Exceptions\FacebookResponseException $e) { // When Graph returns an error echo 'Graph returned an error: ' .
How add Facebook SDK in PHP?php //initialize facebook sdk require 'vendor/autoload. php'; session_start(); $fb = new Facebook\Facebook([ 'app_id' => '1214799411888113', 'app_secret' => '286f08b36691768f859a70e788f4ceda', 'default_graph_version' => 'v2.
How do I get a Facebook access token?Obtain User Access Token. Go to Graph API Explorer.. In Facebook App, select an app used to obtain the access token.. In User or Page, select User Token.. Under Permissions, check ads_read .. Click Generate Access Token. The box on top of the button is populated with the access token.. Store that token for later use.. |