Reputation: 2107
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:
Upvotes: 2
Views: 6611
Reputation: 52083
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>
Upvotes: 2
Reputation: 928
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/
Upvotes: 7