I'm using code from here for login with facebook and this is my first play with Oauth and facebook graph api. Fetching logged in user's details is working fine but when I added code for fetching friend list I got empty array.
<?php
include_once("config.php");
include_once("includes/functions.php");
$friends_list = '';
if(!$fbuser){
$fbuser = null;
$loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
$output = '<a href="'.$loginUrl.'"><img src="images/fb_login.png"></a>';
}else{
$user_profile = $facebook->api('/me?fields=id,first_name,last_name,email,gender,locale,picture');
$friends = $facebook->api('/me/friends','GET');//<-- this line is not working
$user = new Users();
$user_data = $user->checkUser('facebook',$user_profile['id'],$user_profile['first_name'],$user_profile['last_name'],$user_profile['email'],$user_profile['gender'],$user_profile['locale'],$user_profile['picture']['data']['url']);
if(!empty($user_data)){
$output = '<h1>Facebook Profile Details </h1>';
$output .= '<img src="'.$user_data['picture'].'">';
$output .= '<br/>Facebook ID : ' . $user_data['oauth_uid'];
$output .= '<br/>Name : ' . $user_data['fname'].' '.$user_data['lname'];
$output .= '<br/>Email : ' . $user_data['email'];
$output .= '<br/>Gender : ' . $user_data['gender'];
$output .= '<br/>Locale : ' . $user_data['locale'];
$output .= '<br/>You are login with : Facebook';
$output .= '<br/>Logout from <a href="logout.php?logout">Facebook</a>';
$friends_list = $friends;
}else{
$output = '<h3 style="color:red">Some problem occurred, please try again.</h3>';
}
}
?>
<!DOCTYPE html>
<html lang = "en">
<body>
<div class="container">
<div class="col-md-12">
<?php if($output){
echo $output."</br>";
print_r($friends_list);
}
?><br>
</div>
</div>
</body>
</html>
I'm getting print_r($friends_list);
output like Array ( [data] => Array ( ) )
.
My facebook API version is v2.6
and I'm running my script on localhost. So why I'm getting an empty array of friend list, please suggest any changes.