My friend called this like lambda-calculus, even though I know some lambas -- I am still confused how the authorization really works to get the access token.
So please explain this code, hopefully line-by-line. Source of the example is here.
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
P.s. Trying to categorize things here, the q is a sub-problem.
Perhaps related
FB is where all of the Facebooks functions live. All the methods are defined here: https://developers.facebook.com/docs/reference/javascript/ . Login in particular will popup a dialog asking the user to sign in or approve your app.
If they approve your app or have it already added, the response.authResponse will be populated. authResponse also has accessToken, expiry, and UserID. See more details here: https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
This goes to Facebook to ask for the user who just approved/signed into your app. Now you can get the basic information about the user. All the available fields with permissions you need to get them are available here: https://developers.facebook.com/docs/reference/api/user/
This is just getting the name from the user object that you recieved from the
/me
endpoint.This means the user cancelled or did not approve your app so you cannot grab any of their information from Facebook.