Getting Facebook Friends by Gender using Facebook Graph API with PHP SDK
The Facebook Platform for developing apps is not new but i have found there are not enough tutorials available on internet about this platform, when i was learning it i was face the problems and there are not any good tutorial to solve my queries like once i was building an app on which i want to access the Facebook friends by gender then i was face many problems and after searching 3 days on internet then i was found the correct tutorial on it, so i am writing tutorials on this platform, as you see the title of post i am telling you how to access the facebook friends list by gender.
Here is a sample program to access the Facebook friends by gender using Facebook Graph API with PHP SDK, this program is tested by me and works 100%..
Hope this example will help you if you have any query you are free to comment...
More tutorials on Facebook App Development.....
The Facebook Platform for developing apps is not new but i have found there are not enough tutorials available on internet about this platform, when i was learning it i was face the problems and there are not any good tutorial to solve my queries like once i was building an app on which i want to access the Facebook friends by gender then i was face many problems and after searching 3 days on internet then i was found the correct tutorial on it, so i am writing tutorials on this platform, as you see the title of post i am telling you how to access the facebook friends list by gender.
Here is a sample program to access the Facebook friends by gender using Facebook Graph API with PHP SDK, this program is tested by me and works 100%..
<html>
<body>
<?php
$app_id = "YOYR APP ID";
$app_secret = "YOUR APP SECRET";
try
{
include_once ('libs/facebook.php');
}
catch(Exception $o)
{
print_r($o);
}
$fb = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$user = $fb->getUser();
$loginUrl = $fb->getLoginUrl(array
(
'scope' => 'email'
)
);
if ($user)
{
try
{
$fbuser=$fb->api('/me/friends?fields=id,name,gender');
$access_token = $fb->getAccessToken();
} catch (FacebookApiException $e)
{
echo $e;
$user = null;
}
}
if (!$user) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
$count=0;$Mcount=0;
foreach($fbuser['data'] as $friends){
if($friends['gender']=="male")
{
$Mcount++;
echo $friends['name']."<img src='https://graph.facebook.com/".$friends['id']."/picture' width='50' height='50' /><br/>";
}
}
echo "Male Friends Count=".$Mcount;
?>
</body>
</html>
Hope this example will help you if you have any query you are free to comment...
More tutorials on Facebook App Development.....
Thank you so much you solved my problem
ReplyDeleteI have paste the code and running the code i am getting value Zero
ReplyDeleteYou need to download libs/facebook.php file from developers.facebook.com to run this code.
Delete