Forked from biojazzard/facebook_page_latest_post_no_php_sdk.php
Created
June 19, 2017 06:17
-
-
Save kldeepak/60ab0f3bacab7cbd8b9d4498d15ce7ac to your computer and use it in GitHub Desktop.
Revisions
-
biojazzard created this gist
Mar 6, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ <?php /* 1.- Create an App. 2.- Go to: https://developers.facebook.com/tools/explorer/ + Select your new created app on the right top. + Select "Get App Token" 3.- Copy this "{ACCESS-TOKEN}" (is in the form: number|hash) IMPORTANT: (This are not app_id|app_secret!!!) 4.- Query the URL: + https://graph.facebook.com/{PAGE-ID}}/posts?access_token={ACCESS-TOKEN} (5).- Equivalent URL + https://graph.facebook.com/{PAGE-ID}}/feed?access_token={ACCESS-TOKEN} */ function curl_helper($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return json_decode($data); } // Facebook Page: take the last post from here. $page_ID = '{PAGE-ID}'; // Hardcode the App Acces token obtained in point 3. (Server Side Please.) $access_token = '{ACCESS-TOKEN}'; $posts = curl_helper('https://graph.facebook.com/'.$page_ID.'/posts?access_token='.$access_token); $latest_post = $posts->data[0]; list($pageID, $postID) = preg_split('/_/', $latest_post->id); $post_url = 'https://www.facebook.com/'.$pageID.'/posts'.'/'.$postID; $text = '<a href="'.$post_url.'">'.$latest_post->message.'</a>'; echo $text; ?>