检索用户的朋友Facebook API的列表

时间:2014-08-31 17:13:45

标签: php facebook-graph-api

我正在编写一个使用Facebook API的应用程序。在我以前的应用程序中,检索用户的朋友列表很容易(返回了一些包含所有朋友&#id; ID的数组)。

使用当前的API,我找不到一种方法来检索相同的列表。我已经阅读了有关该主题的所有内容(包括S / O和Facebook Dev Docs),但我没有得到最终答案:这样的事情仍然可能。

这是我的代码。

<?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);
}

与朋友有关的任何事情都是空数组或空变数。

0 个答案:

没有答案