-1

I've set scope on the login button, it asks permission for email but can't get email info. i'm testing it so fyi i have a main email and it's approved.

I did this, but it didn't solve my problem: Facebook Email field return null (even if the “email” permission is set and accepted)

This is my code:

define('YOUR_APP_ID', 'x');
define('YOUR_APP_SECRET', 'x');

include_once 'facebook/facebook.php';

$facebook = new Facebook(array(
 'appId' => YOUR_APP_ID,
 'secret' => YOUR_APP_SECRET,
));

$userId = $facebook->getUser();

<script>
window.fbAsyncInit = function() {
 FB.init({
 appId : <?=YOUR_APP_ID?>,
 status : true,
 cookie : true,
 xfbml : true,
 oauth : true,
 });

 FB.Event.subscribe('auth.login', function(response) {
        loading(1);

        <?
        if ($userId) {
        $userInfo = $facebook->api('/' + $userId + '?locale=en_US&fields=id,name,email');  
        }
        ?>
        var mail = "<?=$userInfo['email']?>";

        $.post("<?=$sozlukscripti["path"]?>inc/reglogin.php", { islem: "fbgiris", mail: mail }, function(data) {
            if(data) {
                location.reload();
            }
            else {
                $.pnotify({title: 'giriş başarısız', text: '<? _e("k. adı & mail ya da şifre yanlış"); ?>', type: 'error'});
            }
        loading();
        }); 
        return false;
 });

 };

(function(d){
 var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
 js = d.createElement('script'); js.id = id; js.async = true;
 js.src = "//connect.facebook.net/en_US/all.js";
 d.getElementsByTagName('head')[0].appendChild(js);
 }(document));
</script>

reglogin.php sets sessions for my members. If I set var mail to my email (user@example.com), code works. I can't get email for facebook connect.

my button code:

<div id="fb-root"></div>
<fb:login-button scope="email"></fb:login-button>

thank you in advence.

Community
  • 1
  • 1

1 Answers1

0

Thanks for help(!)

I'm an amatour web designer. So i guess that i made a big mistake in javascript code.

var mail = "<?=$userInfo['email']?>";

Changed javascript code to this:

<?
if ($userId) {
$userInfo = $facebook->api('/' + $userId + '?locale=en_US&fields=id,name,email');
$_SESSION['email'] = $userInfo['email'];
}
?>
var mail = "<?=$_SESSION['email']?>";

now it works. but can someone explain that why it didn't work at the first time?

noob here