“Permalink” for a single facebook post

I queried the wallposts of a facebook page as follows:

require_once 'facebook.php';
$fb = new Facebook(array(
          'appId'  => APP_ID,
          'secret' => APP_SECRET,
            'cookie' => true
$at = $fb->getAccessToken();    
$url = 'https://graph.facebook.com/PAGE_ID/feed?limit=10&access_token='.$at;
$contents = file_get_contents($url);
$FBdata = json_decode($contents);

But not all posts have a link, so I had to create it myself:

foreach($FBdata->data as $k => $data){
        $id_arr = explode("_", $data->id); //get the post ID from PAGEID_POSTID 
        $msg = $data->message; // the message
        $msg = explode("###", wordwrap($msg,50, "###")); //short it down to 50 characters
        $link = 'https://www.facebook.com/PAGEURL/posts/'.$id_arr[1];
        echo "<a href='".$link."'>".$msg[0]."...</a>";

Which means that the link to a single post is as follows: https://www.facebook.com/PAGEURL/posts/POSTID.


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.