Wednesday, January 19, 2011

Grab/Fetch comments from facebook Wall - PHP

The below php code will help you to grab wall comments from the Facebook. You only need to provide profile name(ex: aravindnc) or user id (ex: 1100586621). Please make sure that on the privacy settings in facebook it is set to every one and not friends. You can use the code in what ever place you can, like you can integrate jQuery into it.

<?php
    $ch = curl_init();
    $user = 'aravindnc';
    $graphURL = "http://graph.facebook.com/".$user."/feed?limit=50";
    curl_setopt($ch, CURLOPT_URL,$graphURL);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $contents = curl_exec ($ch);
    $fbComments = array();
    $content = json_decode($contents,true);
    foreach($content as $a=>$value1)
    {
        foreach($value1 as $b=>$value2)
        {
            $list = (array) $value2;
            if($list['message'])
            {
                echo $list['message'].'<br/>';
            }
        }
    }
?>

Here i'm fetching only the user message. Provide your feedback if this helps you.

1 comment:

Unknown said...

Thanks for sharing this useful code. :)

Popular Posts