Pages

Showing posts with label fbml. Show all posts
Showing posts with label fbml. Show all posts

Wednesday, May 18, 2011

Get facebook friends list in an array

Here is the solution for getting facebook friends list in an array usinbg PHP

First of all you need to download latest facebook php sdk from https://github.com/facebook/php-sdk/downloads
 Then include facebook.php from the sdk directory to your php page.

 After that use below code to generate friends list in a array
 --------------------------------------------------------------------------------------------------------
$facebook = new Facebook(array(
  'appId'  => 'APP-ID',
  'secret' => 'APP-SECRET-KEY',
  'cookie' => true,
));

$friends = $facebook->api('/'. FACEBOOK-USER-ID .'/friends');
                $friendsList = array();
                foreach ($friends as $key=>$value)
                {
                   foreach ($value as $fkey=>$fvalue) {

                       $friendsList[] = $fvalue[id];
                   }

                }


print_r($friendsList);
 --------------------------------------------------------------------------------------------------------