简体   繁体   中英

Email permissions not working in Facebook through the JavaScript SDK

I am trying this script:

FB.login({scope: 'email'},function(response){
                if(response.status == 'connected'){
                    alert('I am connected')
                }
            });

But it is not asking the user to give permissions on email.. :(

I tried both scope and perms as parameters.

References:

Found out your mistake, the signature of the function is FB.login(callback function(), {options}), rest is Okay.

FB.login(function(response){
            if(response.status == 'connected'){
                alert('I am connected')
            }
        },{scope: 'email'});

reference: https://developers.facebook.com/docs/reference/javascript/FB.login/

Here is a full working example, just plug in your app id.

<!DOCTYPE html>
<html>
<body>
<div id="fb-root"></div>
<a href="#" onclick="getEmail();return false;">Get Email</a>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
  FB.init({ appId: '**AppID**', status: true, cookie: true, xfbml : true });

  function getEmail() {  
    FB.login(function(response) {
      if (response.session && response.perms) {
        FB.api('/me',  function(response) {
            alert('Email: ' + response.email);
          }
        );
      }
    } , {scope:'email'}); 
}
</script>
</body>
</html>

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