HTML:
Basically, once the login is done, you will call in the callLoginMethod() method that will display the information.
<div class="fb-login-button" data-scope="email,user_birthday,user_hometown,user_location,user_location" data-max-rows="1" data-size="medium" data-show-faces="false" data-auto-logout-link="false" onlogin="callLoginMethod();" login_text="Entrar com o Facebook"> </div>
Javascript:
window.fbAsyncInit = function() {
FB.init({
appId : SEU_APP_ID,
xfbml : true,
version : 'v2.8'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function basicAPIRequest() {
FB.api('/me',
{fields: "id,picture,birthday,email,first_name,gender,name,location,hometown"},
function(response) {
console.log('Resposta:', response);
}
);
}
function callLoginMethod() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
basicAPIRequest();
} else {
FB.login();
}
});
}
Okay, Thiago, the problem is not in the code. I have already tested with the SDK and the API in PHP, the problem is that when you accept the use of the app it does not ask for such information, only the name, gender and age that are public profile data. What I can not understand is why it does not release the request for Email, and by Developers.facebook in my app shows how released.
– William
Go to the user’s facebook page, delete the application and repeat the process. I just made a page, with a newly created application ( that in case I do not have permission for anything, only email, name and id.) and used the code above to receive the information. My application is not even public, it is in development mode and only works properly for now with the developer profile.
– Thiago Prado
Did you put the email permissions in the function Scope? put the code on the page.
– Thiago Prado
Really Thiago, it was my mistake in Scope... Thanks for the help!
– William