php中的fb登录错误

时间:2016-01-11 17:17:33

标签: facebook facebook-login

我用php创建fb登录, 问题是用户的电子邮件没有从Facebook返回, FBID和USER NAME正在返回。

我为另一个项目所做的相同代码正在运行,但是新代码无效

代码就像这样

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

if ($user) {
    try {
        $user_profile = $facebook->api('/me');
        $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
        /* ---- Session Variables -----*/
        $_SESSION['FBID'] = $fbid;
        $_SESSION['USERNAME'] = $fbuname;
        $_SESSION['FULLNAME'] = $fbfullname;
        $_SESSION['EMAIL'] = $femail;

    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}
if ($user) {
    header("location:fblogin.php");
} else {
    $loginUrl = $facebook->getLoginUrl(array(
        'scope' => 'email', // Permissions to request from the user
    ));
    header("location: " . $loginUrl);
}

1 个答案:

答案 0 :(得分:0)

svnadmin freeze

它被称为“声明字段”,请参阅changelog。顺便说一下,你再也找不到用户名了。