title: Get user friends list using PHP and facebook API
body: <p>So I'm using CodeIgniter framework and trying to get user friends. I have no problems with authentification, but when I try to get user friends using GET method from <code>https://graph.facebook.com/me/friends?fields=gender,id,name&amp;access_token=</code> it returns me empty array. This is the front end code</p>
  
  <pre><code>&lt;script&gt;
  $(function () {
      FB.init({
          appId: ****, // App ID
          channelUrl: '', // Channel File
          status: true, // check login status
          cookie: true, // enable cookies to allow the server to access the session
          xfbml: true  // parse XFBML
      });
  });
  
  jQuery('*[data-action="doFbLogin"]').on('click', function () {
      FB.login(function (response) {
          if (response.authResponse) {
  
              FB.api('/me/friends', function(response) {
  
                  // loading message
                  var intervalLoading = 0;
                  setInterval(function() {
                      intervalLoading = ++intervalLoading % 4;
                      jQuery('*[data-message="fb_loading"]').html("Connecting, please wait" + Array(intervalLoading + 1).join("."));
                  }, 400);
  
                  // request
                  jQuery.post('http://www.****.***/ajax/fb_connect', {
                          "user_id": response.id,
                          "full_name": response.name,
                          "first_name": response.first_name,
                          "last_name": response.last_name,
                          "email": response.email,
                          "gender": response.gender,
                          "token": response.token,
                          "friends": response.friends,
                          "current_url": 'http://*****',
                          "ref_url": 'http://*****'
                      },
                      function (data) {
                          data = JSON.parse(data);
                          if (data == true) {
                              jQuery('*[data-message="fb_loading"]').removeAttr('data-message').html('Connected!');
                              location.reload();
                          } else {
                              jQuery('*[data-message="fb_loading"]').removeAttr('data-message').html('Connection failed!');
                              setTimeout(function(){
                                  location.reload();
                              }, 2000);
                          }
                      }
                  );
              });
          } else {
              console.log('something went wrong');
          }
      }, {scope: 'email'});
  });
  </code></pre>
  
  <p></p>
  
  <p>and this is my backend - connection:</p>
  
  <pre><code>$data = array(
          'fb-config' =&gt; array(
              'appId'  =&gt; FACEBOOK_API_ID,
              'secret' =&gt; FACEBOOK_SECRET
          )
      );
  
      $this-&gt;load-&gt;library('facebook', $data['fb-config']);
      $data['userData'] = $this-&gt;facebook-&gt;getUser();
  
      if ( $data['userData'] ) {
          try {
              $data['user_profile'] = $this-&gt;facebook-&gt;api('/me');
          } catch (FacebookApiException $e) {
              $data['user_profile'] = null; // return false, execution terminated.
              $this-&gt;facebook-&gt;destroySession();
          }
      }
  
  $this-&gt;session-&gt;set_userdata(array('user_fb_token' =&gt; $this-&gt;facebook-&gt;getAccessToken()));
              print_r($this-&gt;users_model-&gt;getUserFacebookFriends());
              exit;
  </code></pre>
  
  <p>and method to get friends:</p>
  
  <pre><code>public function getUserFacebookFriends()
  {
      // get facebook friends (crawl)
      $graph_link = 'https://graph.facebook.com/me/friends?fields=gender,id,name&amp;access_token=';
      $user_friends = file_get_contents($graph_link . $this-&gt;session-&gt;userdata('user_fb_token'));
  
      $friendsArray = json_decode($user_friends, true);
  
      if ( is_array($friendsArray) ) {
          $data = array('friendsArray' =&gt; $friendsArray['data']);
      } else {
          $data = array('friendsArray' =&gt; FALSE);
      }
  
      return $data;
  }
  </code></pre>
  
  <p>so I have no idea why this is not working, any suggestions?</p>