简体   繁体   中英

Facebook login - can not retrieve email address

I am creating a login function for my website, using the FB login API.

I use https://graph.facebook.com/oauth/access_token?client_id=ID&redirect_uri=URL&client_secret=SECRET&code=CODE

I am able to retrieve name and basics. But email I can not get.

In my app, I have set permissisions, including "email". But still, when the APP says "WEBSITE wants access to your information and friend list" the email option is not mentioned.

What am I doing wrong?

Best regards, Rasmus

You must include the scope parameter and the redirect parameter.

$config = array();
$config['appId'] = 'xxx';
$config['secret'] = 'xxx';

$facebook = new Facebook($config);

if(isset($_GET['act']) && $_GET['act'] == "logout") {
    $facebook->destroySession();
}


$user = $facebook->getUser();
echo $user;
if ($user) {

    try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
    } catch (FacebookApiException $e) {
    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
    $user = null;
    }
    echo "<pre>";
    print_r($user_profile);
    echo "</pre>";  
    $logout = $facebook->getLogoutUrl();

    //echo $logout;

    echo "<a href='test.php?act=logout'>Logout</a>";


} else {

    $login = $facebook->getLoginUrl(array("scope"=>"email","display"=>"popup","redirect_uri"=>"http://domain.com/test.php"));

    echo "<a href='".$login."'>Login</a>";

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM