0

I am coding an app that uses the Facebook API. In my previous apps, retrieving a user's friend list was easy (some array with all the friends' ids was returned).

With the current API, I cannot found a way to retrieve the very same list. I have read everything that's available on the topic (both S/O and Facebook Dev Docs) but I don't have the final answer: is such a thing still possible.

Here's my code.

<?php
require 'src/facebook.php';  // Include facebook SDK file
//require 'functions.php';  // Include functions
$facebook = new Facebook(array(
  'appId'  => 'xxxx',   // Facebook App ID 
  'secret' => 'xxxx',  // Facebook App Secret
  'cookie' => true, 
));
$user = $facebook->getUser();

if ($user) {
  try {
    $user_profile = $facebook->api('/me');
    $user_friends = $facebook->api('/me/friends');
        $fbid = $user_profile['id'];                 // To Get Facebook ID
        $fbuname = $user_profile['username'];  // To Get Facebook Username
        $fbfullname = $user_profile['name']; // To Get Facebook full name
        $femail = $user_profile['email'];    // To Get Facebook email ID



$friends=implode($user_friends,','); 



$link = mysql_connect("localhost", "xxx", "xxx")
    or die("Impossible de se connecter : " . mysql_error());


mysql_select_db('mirror',$link); 


$sql = "SELECT * FROM users  WHERE email = '".$femail."'  "; 

// on envoie la requête 
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); 

$num_rows = mysql_num_rows($req);



if($num_rows==0){ 

$sql = "INSERT INTO users (email, name, fbid,friends) VALUES ('".$femail."','".utf8_decode($fbfullname)."','".$fbid."','".$friends."') "; 

// on envoie la requête 
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); 

}

if($num_rows!=0){ 

$sql = "UPDATE users SET  fbid = '".$fbid."',friends='".$friends."'  "; 

// on envoie la requête 
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); 

}






    /* ---- Session Variables -----*/
        $_SESSION['FBID'] = $fbid;           
        $_SESSION['USERNAME'] = $fbuname;
            $_SESSION['FULLNAME'] = $fbfullname;
        $_SESSION['EMAIL'] =  $femail;
    //       checkuser($fbid,$fbuname,$fbfullname,$femail);    // To update local DB
  } catch (FacebookApiException $e) {
    error_log($e);
   $user = null;
  }
}
if ($user) {


  header("Location: index.php");
} else {
 $loginUrl = $facebook->getLoginUrl(array(
        'scope'     => 'email , user_likes, read_friendlists'

        ));
 header("Location: ".$loginUrl);
}

anything related to friends is either an empty array or an empty var.

justberare
  • 901
  • 1
  • 8
  • 26
  • The new Facebook APIs will just return the list of friends who *use your application*, not the complete one. You can read more here: http://stackoverflow.com/a/23417628/3456807 –  Aug 31 '14 at 17:18
  • Thanks a lot @Angelo - Super Clear - No way around then.. – justberare Aug 31 '14 at 17:19
  • You're welcome :) I'm afraid there isn't –  Aug 31 '14 at 17:20
  • possible duplicate of [Facebook Graph Api v2.0 me/friends returns empty, or only friends who also use my app](http://stackoverflow.com/questions/23417356/facebook-graph-api-v2-0-me-friends-returns-empty-or-only-friends-who-also-use-m) – Igy Sep 02 '14 at 05:54

0 Answers0