AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



facebook-login: I want to add login with facebook on my website

I have created the app for my website on facebook, but i am not able to get the email id of the user. Please help me.

facebook x 2
login x 5
Posted On : 2013-12-17 23:23:43.0
profile Garima Gupta - anyforum.in Garima Gupta
596129558962
up-rate
4
down-rate

Answers


To get the additional information you just need to focus on user´s scope. When user click on facebook login button it calls the FB.login(). Now if you want to receive the user´s email then replace FB.login() with FB.login(function(response) { }, {scope: ´email´}); in script code. and also onclick event of the facebook code.

Following is the javascript code to put on your webpage. and replace the App ID you recently generated while creating the app.
----------------------------------------------------------------------------------------------------------------------------------
window.fbAsyncInit = function() {
FB.init({
appId : ´xxxxxxxxxxxxxxxxx´,
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe(´auth.authResponseChange´, function(response) {
if (response.status === ´connected´) {
testAPI();
} else if (response.status === ´not_authorized´) {
FB.login(function(response) {
}, {scope: ´email´});
} else {
FB.login(function(response) {
}, {scope: ´email´});
}
});
};
(function(d){
var js, id = ´facebook-jssdk´, ref = d.getElementsByTagName(´script´)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(´script´); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
function testAPI() {
console.log(´Welcome! Fetching your information.... ´);
FB.api(´/me´, function(response) {
document.getElementById(´name´).innerHTML=response.name;
document.getElementById(´email´).innerHTML=response.email;
});
}
function fblogin(){FB.login(function(response){ }, {scope: ´email´});}
----------------------------------------------------------------------------------------------------------------------------------

Following is the HTML code for button, You can customize the button , just call the fblogin() defined in javascript with onclick event.

----------------------------------------------------------------------------------------------------------------------------------

<a style="background:none;cursor:pointer;" onclick="fblogin()"><img alt="login with facebook - anyforum.in" src="/images/fblogin.png" /></a>

<div id="name"></div>
<div id="email"></div>

Posted On : 2013-12-17 23:36:39
Satisfied : 1 Yes  0 No
profile Saksham Kumar - anyforum.in Saksham Kumar
73433939091
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in