Some notes about the provided example in Facebook Javascript SDK in the login documentation
FB.login(function(response) {
// Here the authResponse is available for us to be used.
// inside it we can debug the access token, it's expiration, granted permissions etc. : in example
// reference for the FB.login fromat: https://developers.facebook.com/docs/facebook-login/web
console.log('Granted scopes are: ' + response.authResponse.grantedScopes);
console.log('Access token is' + response.authResponse.accessToken);
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', {fields: 'email'},function(response) {
// authResponse isn't available here
// this response is very specific, it has the information we need
// notice that the fields we ask for here may need some permissions to be granted first
// reference for the fields and their permissions https://developers.facebook.com/docs/facebook-login/permissions
// reference for the FB.api call format https://developers.facebook.com/docs/javascript/reference/FB.api
// note: default response contents is the name and user id only
console.log('Good to see you, ' + response.name + '.');
console.log('Your email is ' + response.email);
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {
scope: 'email,publish_actions',
// scope has the permissions we ask for specified into. Every time we update this line with an extra permission
// the user will only prompted by this extra permission
return_scopes: true
// by returning scopes we expect authResponse to include a list of all the granted permissions returned so that we can debug them
}
);