Simon McManus

Javascript Engineer

Get your friends details out of Facebook

The below code outputs a HTML table showing all of your facebook friends and their details.  You will need to include the code on a PHP server where you have already registered your application.

This code is far from finished, but provides a very good starting point because it shows how you can access each of the variables.

<?php
require\_once 'facebook.php';
$friends = $facebook->api\_client->friends\_get();
echo '<table border=1>';
foreach($friends as $friend)
{
&nbsp;&nbsp;&nbsp; echo '<tr>';
&nbsp;&nbsp;&nbsp; echo '<td>';
&nbsp;&nbsp;&nbsp; $name = $facebook->api\_client->users\_getInfo($friend,'name, pic\_small, birthday, sex, hometown\_location, meeting\_sex, meeting\_for, affiliations, relationship\_status, significant\_other\_id, political, current\_location, activities, interests, music, tv, about\_me, work\_history, education\_history, status');
&nbsp;&nbsp;&nbsp; echo "<img src='".str\_replace('/http', '', str\_replace('.jpg/','', $name\[0\]\[pic\_small\]))."'/>";
&nbsp;&nbsp;&nbsp; echo ' </td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[name\];
&nbsp;&nbsp;&nbsp; echo ' </td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[birthday\];
&nbsp;&nbsp;&nbsp; echo ' </td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[sex\];
&nbsp;&nbsp;&nbsp; echo '</td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[hometown\_location\]\[city\].', ';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[hometown\_location\]\[state\].', ';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[hometown\_location\]\[country\].', ';
&nbsp;&nbsp;&nbsp; echo '</td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[meeting\_sex\];
&nbsp;&nbsp;&nbsp; echo '</td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[meeting\_for\];
&nbsp;&nbsp;&nbsp; echo ' </td><td>';
&nbsp;&nbsp;&nbsp; echo ' </td><td>';
//&nbsp;&nbsp;&nbsp; echo var\_dump($name\[0\]\[affiliations\]);
&nbsp;&nbsp;&nbsp; foreach ($name\[0\]\[affiliations\] as $aff)
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp; echo '<ul>';
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; foreach ($aff as $aff\_det)
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo '<li>'.$aff\_det.'</li>';
&nbsp;&nbsp;&nbsp; echo '</ul>';
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; echo ' </td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[relationship\_status\];
&nbsp;&nbsp;&nbsp; echo '</td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[significant\_other\_id\];
&nbsp;&nbsp;&nbsp; echo ' </td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[political\];
&nbsp;&nbsp;&nbsp; echo '</td><td>';
&nbsp;&nbsp;&nbsp; echo '<ul>';
&nbsp;&nbsp;&nbsp; foreach ($name\[0\]\[current\_location\] as $aff)
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo '<li>'.$aff.'</li>';
&nbsp;&nbsp;&nbsp; echo '</ul>';
&nbsp;&nbsp;&nbsp; //echo $name\[0\]\[current\_location\];
&nbsp;&nbsp;&nbsp; echo '</td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[activities\];
&nbsp;&nbsp;&nbsp; echo ' </td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[interests\];
&nbsp;&nbsp;&nbsp; echo ' </td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[music\];
&nbsp;&nbsp;&nbsp; echo '</td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[tv\];
&nbsp;&nbsp;&nbsp; echo ' </td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[about\_me\];
&nbsp;&nbsp;&nbsp; echo ' </td><td>';
&nbsp;&nbsp;&nbsp; echo $name\[0\]\[work\_history\];
&nbsp;&nbsp;&nbsp; echo ' </td><td>';
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; foreach ($name\[0\]\[education\_history\] as $aff)
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp; echo '<ul>';
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; foreach ($aff as $aff\_det)
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo '<li>';
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo arrayToXML($aff\_det);
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo '</li>';
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; echo '</ul>';
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; //echo $name\[0\]\[education\_history\];
&nbsp;&nbsp;&nbsp; echo '</td><td>';
&nbsp;&nbsp;&nbsp; if ($name\[0\]\[status\]\[time\]!=0)
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo $name\[0\]\[status\]\[message\].' - '.date("Y/m/d", $name\[0\]\[status\]\[time\]).'</td></tr>';
}
echo '</table>';
?>
August 9th 2007