Reputation: 35
I have created test app in developer facebook. Trying to get facebook friend list using App id and app Secret.i have created Follow code
<?php
//facebook application configuration
$fbconfig['appid' ] = "xxxxxxxxxxxxxxxxxxxx";
$fbconfig['secret'] = "xxxxxxxxxxxxxxxxxxxx";
try{
include_once ('.\facebook-php-sdk-master\src\facebook.php');
}
catch(Exception $o){
print_r($o);
}
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'cookie' => true,
));
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'email'
)
);
if ($user) {
try {
$user_profile = $facebook->api('/me');
$user_friends = $facebook->api('/me/friends');
$access_token = $facebook->getAccessToken();
} catch (FacebookApiException $e) {
d($e);
$user = null;
}
}
if (!$user) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
$total_friends = count($user_friends['data']);
echo 'Total friends: '.$total_friends.'.<br />';
$start = 0;
while ($start < $total_friends) {
echo $user_friends['data'][$start]['name'];
echo '<br />';
$start++;
}
?>
Finally Run the code in My localhost its showing friend List zero Like this
Total friends: 0.
but I have 2 friends.please any idea about how to resolve my issues? thanks in advance ?
Upvotes: 1
Views: 143
Reputation: 74004
You need to authorize with the user_friends
permission. After that, you can use /me/friends
to get friends who authorized your App with user_friends
too (and only those). It is not possible to get all friends anymore, except for tagging (taggable_friends) or inviting friends to a canvas game (invitable_friends). Check out the changelog to find out about more changes: https://developers.facebook.com/docs/apps/changelog
For more information, check out the answer of this thread, it´s from a Facebook employee: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app
Upvotes: 2
Reputation: 587
facebook returns your friends list in two scenarios only.
before getting friends list please check that your app was approved with proper permissions by facebook.
Upvotes: -1