检索facebook好友列表,返回null

时间:2015-03-30 13:33:00

标签: facebook facebook-graph-api facebook-php-sdk

我正在使用facebook sdk for php来检索所选用户的facebook好友列表

我使用的代码如下

 <?php
 session_start();
 // added in v4.0.0
 require_once 'autoload.php';
 use Facebook\FacebookSession;
 use Facebook\FacebookRedirectLoginHelper;
 use Facebook\FacebookRequest;
 use Facebook\FacebookResponse;
 use Facebook\FacebookSDKException;
 use Facebook\FacebookRequestException;
 use Facebook\FacebookAuthorizationException;
 use Facebook\GraphObject;
 use Facebook\Entities\AccessToken;
 use Facebook\HttpClients\FacebookCurlHttpClient;
 use Facebook\HttpClients\FacebookHttpable;
 // init app with app id and secret
 FacebookSession::setDefaultApplication(      '1481363705467343','5cdb2c0a08c222dda7bab850eb14f6de' );
 // login helper with redirect_uri
     $helper = new      FacebookRedirectLoginHelper('http://localhost/facebook/fbconfig.php' );
 try {
   $session = $helper->getSessionFromRedirect();
 } catch( FacebookRequestException $ex ) {
   // When Facebook returns an error
 } catch( Exception $ex ) {
   // When validation fails or other local issues
 }
 // see if we have a session
 if ( isset( $session ) ) {
   // graph api request for user data
   $request = new FacebookRequest( $session, 'GET', '/me' );
   $response = $request->execute();
   var_dump($response);
   $request1 = new FacebookRequest( $session, 'GET',      '/me/permissions/user_friends' );
   $response1 = $request1->execute();
   var_dump($response1);

   // get response
   $graphObject = $response->getGraphObject();
        $fbid = $graphObject->getProperty('id');              // To Get Facebook ID
        $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
         $femail = $graphObject->getProperty('email');    // To Get Facebook email ID
/* ---- Session Variables -----*/
        $_SESSION['FBID'] = $fbid;           
         $_SESSION['FULLNAME'] = $fbfullname;
        $_SESSION['EMAIL'] =  $femail;
     /* ---- header location after session ----*/
   //header("Location: index.php");
 } else {
   $loginUrl = $helper->getLoginUrl();
  header("Location: ".$loginUrl);
 }
 ?>

我得到的结果对于'我/朋友'是空的,但是如果我使用'我/'我可以检索所选用户的详细信息

请有人建议解决方案

提前致谢

1 个答案:

答案 0 :(得分:1)

  

/me/friends端点不再包含某人朋友的完整列表。相反,它现在返回该人的朋友列表,他们也在使用您的应用程序。