title: Facebook friend counter
body: <p>What I'm trying to do is a counter of facebook friends in php, so the result of the code would be something like "You have 1342 Friends!".</p>
  
  <p>So this is the code im using:</p>
  
  <pre><code>&lt;?php 
  
  require_once("../src/facebook.php");
  
      $config = array();
      $config[‘appId’] = 'MY_APP_ID';
      $config[‘secret’] = 'MY_APP_SECRET';
      $facebook = new Facebook($config);
      $user_id = "MY_USER_ID";
  
        //Get current access_token
      $token_response = file_get_contents
        ("https://graph.facebook.com/oauth/access_token?
        client_id=$config[‘appId’]
        &amp;client_secret=$config[‘secret’]
        &amp;grant_type=client_credentials"); 
  
  
    // known valid access token stored in $token_response
    $access_token = $token_response;
  
    $code = $_REQUEST["code"];
  
    // If we get a code, it means that we have re-authed the user 
    //and can get a valid access_token. 
    if (isset($code)) {
      $token_url="https://graph.facebook.com/oauth/access_token?client_id="
        . $app_id  
        . "&amp;client_secret=" . $app_secret 
        . "&amp;code=" . $code . "&amp;display=popup";
      $response = file_get_contents($token_url);
      $params = null;
      parse_str($response, $params);
      $access_token = $params['access_token'];
    }
  
  
    // Query the graph - Friends Counter:
  $data = file_get_contents
  ("https://graph.facebook.com/$user_id/friends?" . $access_token );
  $friends_count = count($data['data']); 
  echo "Friends: $friends_count";
  
  echo "&lt;p&gt;$data&lt;/p&gt;"; //to test file_get_contents
  
  ?&gt;
  </code></pre>
  
  <p>So, the result of the echo $Friends_count its always "1".</p>
  
  <p>And then I test $data with an echo and it give me the list of all the friends so it is getting the content but its not counting it right... how could i fix it?</p>
  
  <p>I've already tried changing the</p>
  
  <pre><code>$friends_count = count($data['data']); 
  </code></pre>
  
  <p>for</p>
  
  <pre><code>$friends_count = count($data['name']);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$friends_count = count($data['id']);
  </code></pre>
  
  <p>but the result is always "1".</p>
  
  <hr>
  
  <p>The result of the above code looks like this;</p>
  
  <pre><code>Friends: 1
  
  {"data":[{"name":"Enny Pichardo","id":"65601304"},{"name":"Francisco Roa","id":"500350497"},etc...]
  </code></pre>