We are using facebook for login in our website.
We need email as a mandatory permission. If the user doesn't grant email permission then the dialog should give an alert() message saying 'Please grant email permission' and repeat.
I have seen this feature in few of the shopping sites. The below code works fine but doesn't have the feature I mentioned.
Help needed.
window.fbAsyncInit = function () {
FB.init({
appId: 'MY APP ID',
oauth: true,
status: false, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
};
function fb_login() {
FB.login(function (response) {
if (response.authResponse) {
access_token = response.authResponse.accessToken; //get access token
user_id = response.authResponse.userID; //get FB UID
FB.api('/me', function (response) {
// you can store this data into your database
alert(response.email);
});
}
}, {
scope: 'email'
});
}
(function () {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
} ());
Somewhere in the body of HTML.
<div class="span"><a onclick="fb_login();"><img src="css/images/facebook.png" alt=""/><sm>Sign In with Facebook</sm><div class="clear"></div></a></div>
Have a look at
especially the "Handling Missing Permissions" part of the first link.