1

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 ?

arasu
  • 35
  • 1
  • 6
  • You will only get back friends that have granted user_friends permission to your app – WizKid Jul 25 '15 at 06:02
  • then sir how to get all friends in my list ? i have to give permission for my app ? – arasu Jul 25 '15 at 06:04
  • You can't. You can only get friends that granted user_friends permission to your app – WizKid Jul 25 '15 at 06:07
  • one more doubt sir..how i will give granted user_permission for my app – arasu Jul 25 '15 at 06:19
  • You show them the login dialog. Ask for user_friends – WizKid Jul 25 '15 at 06:23
  • i have give permission and get login dialog.but still i am get friends list 0 i get answer in Graph API Explorer . i am trying to Run my code Localhost getting value 0. but I am getting answer Graph API Explorer Looks like { "data": [ { "uid": "479775018857904", "name": "Thenn Arasu" } ] } – arasu Jul 25 '15 at 07:22
  • Your friends needs to grant the permission also – WizKid Jul 25 '15 at 16:11

2 Answers2

2

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

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
-1

facebook returns your friends list in two scenarios only.

  1. Your app must be in Gaming category.
  2. If your app not comes under games, then it will only returns the list of your friends who liked that particular app.

before getting friends list please check that your app was approved with proper permissions by facebook.

Syam Danda
  • 587
  • 3
  • 12
  • 34
  • it does not matter if a friend liked an app or not. and you don´t need to get the required permission approved. taggable_friends would work for non-games too. sorry, but the whole answer is completely wrong and misleading. – andyrandy Jul 25 '15 at 08:44