Get Friends Photo on local website by facebook sdk

<?php
include “src/facebook.php”;
$facebook =new Facebook(array(
‘appId’=>’your app id’,
‘secret’=>’your key’,
‘cookie’=>true
));
$session=$facebook->getUser();
$me=null;

if($session)
{
try
{

$me=$facebook->api(“/me/friends”);
//print_r($me);

$token=$facebook->getAccessToken();

$fbl=”select name,username,pic_square,uid from user where uid=”.$session;
$param=array(
‘method’=>’fql.query’,
‘query’=>$fbl,
‘callback’=>”
);                                    $my_details =$facebook->api($param);
$my_details=$my_details[0];
echo “<img src=”.$my_details[‘pic_square’].”>”;

echo “<h1>MY FRIENDS</h1>”;
$fb2=”select name,username,pic_square,uid from user where uid in(select uid1 from friend where uid2=”.$session.”)”;
$param2=array(
‘method’=>’fql.query’,
‘query’=>$fb2,
‘callback’=>”
);
$friend_list=$facebook->api($param2);
//print_r($friend_list);
$i=1;
foreach($friend_list as $fri)
{
if(($i-1)%10==0)
{
echo ‘</ul><div style=”clear:both”></div><ul style=”padding:0px”>’;
}
?>
<li style=”float:left;list-style:none;margin:5px;position:relative;”>
<div id=”pw<?php echo $i; ?>”  >

<table>
<td width=”60px” valign=”top”><img src=”<?php echo $fri[‘pic_square’]; ?>” title=”<?php echo $fri[‘name’]; ?>”></td>
</table>
</div>
</li>

<?
$i++;
}
}catch(FacebookApiException $e)
{
echo $e->getMessage();
}
}
if($me)
{
$logoutUrl=$facebook->getLogoutUrl();
echo “<a href=$logoutUrl>Logout</a>”;

}
else
{
$loginUrl=$facebook->getLoginUrl(array(‘scope’ =>’publish_stream’));
echo “<a href=$loginUrl>Login</a>”;
}
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s