Facebook Apps – Get User’s Friends and List

For your apps see User Friend Ids and in which Friendlist friend is.

Use these 2 files:

  • index.php
  • friendlists_data.php

For index.php,

[php]<?php
$colnams="
flid,
uid
";

$pgno="1";
$defaultresultrownum="5";
$lowerlimit=($pgno-1)*$defaultresultrownum;
$upperlimit=$defaultresultrownum;

$searchtbnam="friendlist_member";
$wherequery = "WHERE flid IN (SELECT flid FROM friendlist WHERE owner=’$fbuid’)";
//$wherequery = "";
$resultsort="uid";
$resultsortorder="asc";
$orderby="ORDER BY $resultsort $resultsortorder";
//$limit="LIMIT $lowerlimit,$upperlimit";

$fql    =  "SELECT $colnams FROM $searchtbnam $wherequery $orderby $limit";
$param  =   array(
‘method’     => ‘fql.query’,
‘query’     => $fql,
‘callback’    => ”
);
$_friends   =   $facebook->api($param);

//$friends_already_using_count=count($_friends);
//d($_friends);
$friends = $_friends;
$friends_count=count($friends);
if($friends_count>’0′)
{
echo "<b>$friends_count Friend Lists<b><br>";
include "friendlists_data.php";
}
?>[/php]

For friendlists_data.php,

[php]<?php
echo "<table border=’1′ width=’100%’>";
echo "<tr>
<th>S.No.</th>
<th>FB UID</th>
<th>Friend List</th>
</tr>";

for($i=0; $i<$friends_count; $i++)
{
$sno=$i+1;
$friend_uid=$friends[$i][uid];
$friend_listid=$friends[$i][flid];

echo "<tr>
<td>$sno</td>
<td>$friend_uid</td>
<td>$friend_listid</td>
</tr>";

}
echo "</table>";
?>
[/php]

Leave a Comment