0

我无法从 Graph 对象中检索电子邮件。我在我的应用程序上看到我有权使用它。这是我当前的代码:

    FacebookSession::setDefaultApplication('xxx','xx');
    $helper = new FacebookRedirectLoginHelper('xxx');
    $session = null;
    try {
        $session = $helper->getSessionFromRedirect();
        Core::session('FacebookAuthSession')->sessionObject = $session;
    } catch(FacebookRequestException $ex) {

    } catch(\Exception $ex) {

    }
    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();
    $graphObject = $response->getGraphObject(); 
4

2 回答 2

0

您可以使用以下代码执行:

use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;

if($session) {

  try {

    $user_profile = (new FacebookRequest(
      $session, 'GET', '/me'
    ))->execute()->getGraphObject(GraphUser::className());

    echo "Email: " . $user_profile->getEmail();

  } catch(FacebookRequestException $e) {

    echo "Exception occured, code: " . $e->getCode();
    echo " with message: " . $e->getMessage();

  }   

}

要测试结果,您还可以使用资源管理器:https ://developers.facebook.com/tools/explorer

于 2014-11-10T19:39:58.173 回答
0

权限在您的应用程序设置中仅列为“未经审查批准”,但您仍然必须通过在登录过程中使用“范围”参数向用户授权:https ://developers.facebook.com/docs/参考/php/facebook-getLoginUrl/

于 2014-11-10T19:56:08.150 回答