"Permalink" for a single facebook post

September 03, 2012 at 08:10

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.  

Tags: feed permalink post wallpost

Hinterlasse einen Kommentar: