This tutorial is based on the Facebook Apps development. I have found there are very few tutorials on Facebook Apps development so i decided to give the series of Facebook Apps Tutorials here.
In this tutorial i am teach you that How to access female friends only and display them using Facebook Graph API with PHP sdk......
The Code for accessing and displaying the Female friends only is shown below....
Learn How to Create Facebook App
Learn How to Get App ID and App Secret
Learn How To Create a Facebook App
In this tutorial i am teach you that How to access female friends only and display them using Facebook Graph API with PHP sdk......
The Code for accessing and displaying the Female friends only is shown below....
Learn How to Create Facebook App
Learn How to Get App ID and App Secret
<html> <body> <?php $app_id = "YOUR 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']=="famale") { $Mcount++; echo $friends['name']."<img src='https://graph.facebook.com/";.$friends['id']."/picture' width='50' height='50' /><br/>"; } } echo "Female Friends Count=".$Mcount; ?> </body> </html>
To get AppId and secret you have to create an App using your Facebook account...
Learn How To Create a Facebook App
wow this is what i am searching for last copula of days that's really great graph API. thanks fro shearing wonderful post...
ReplyDeleteIf I Know User id and i want to get gender. can is use with this...?
ReplyDeleteEx:$fbuser=$fb->api('/43434343434343/friends?fields=id,name,gender');
Dose it can get Gender by no need allow permission?
It can get gender but you need permissions from fb to get anything using code.
ReplyDelete