Skip to content

Instantly share code, notes, and snippets.

@weshouman
Created September 15, 2016 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weshouman/ec6c0a981f1149b9bd24ad8ffc47565d to your computer and use it in GitHub Desktop.
Save weshouman/ec6c0a981f1149b9bd24ad8ffc47565d to your computer and use it in GitHub Desktop.
facebook login experience

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
			}
);

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment