Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. <script>
  2. // This is called with the results from from FB.getLoginStatus().
  3. function statusChangeCallback(response) {
  4. console.log('statusChangeCallback');
  5. console.log(response);
  6. // The response object is returned with a status field that lets the
  7. // app know the current login status of the person.
  8. // Full docs on the response object can be found in the documentation
  9. // for FB.getLoginStatus().
  10. if (response.status === 'connected') {
  11. // Logged into your app and Facebook.
  12. testAPI();
  13. } else if (response.status === 'not_authorized') {
  14. // The person is logged into Facebook, but not your app.
  15. document.getElementById('status').innerHTML = 'Please log ' +
  16. 'into this app.';
  17. } else {
  18. // The person is not logged into Facebook, so we're not sure if
  19. // they are logged into this app or not.
  20. document.getElementById('status').innerHTML = 'Please log ' +
  21. 'into Facebook.';
  22. }
  23. }
  24.  
  25. // This function is called when someone finishes with the Login
  26. // Button. See the onlogin handler attached to it in the sample
  27. // code below.
  28. function checkLoginState() {
  29. FB.getLoginStatus(function(response) {
  30. statusChangeCallback(response);
  31. });
  32. }
  33.  
  34. window.fbAsyncInit = function() {
  35. FB.init({
  36. appId : 1768080543471882,
  37. cookie : true, // enable cookies to allow the server to access
  38. // the session
  39. xfbml : true, // parse social plugins on this page
  40. version : 'v2.7' // use graph api version 2.7
  41. });
  42.  
  43. // Now that we've initialized the JavaScript SDK, we call
  44. // FB.getLoginStatus(). This function gets the state of the
  45. // person visiting this page and can return one of three states to
  46. // the callback you provide. They can be:
  47. //
  48. // 1. Logged into your app ('connected')
  49. // 2. Logged into Facebook, but not your app ('not_authorized')
  50. // 3. Not logged into Facebook and can't tell if they are logged into
  51. // your app or not.
  52. //
  53. // These three cases are handled in the callback function.
  54.  
  55. FB.getLoginStatus(function(response) {
  56. statusChangeCallback(response);
  57. });
  58.  
  59. };
  60.  
  61. // Load the SDK asynchronously
  62. (function(d, s, id) {
  63. var js, fjs = d.getElementsByTagName(s)[0];
  64. if (d.getElementById(id)) return;
  65. js = d.createElement(s); js.id = id;
  66. js.src = "//connect.facebook.net/en_US/sdk.js";
  67. fjs.parentNode.insertBefore(js, fjs);
  68. }(document, 'script', 'facebook-jssdk'));
  69.  
  70. // Here we run a very simple test of the Graph API after login is
  71. // successful. See statusChangeCallback() for when this call is made.
  72. function testAPI() {
  73. console.log('Welcome! Fetching your information.... ');
  74. FB.api('/me?fields=id,name,email,first_name,last_name', function(response) {
  75. console.log('Successful login for: ' + response.email + ' ' + response.first_name + ' ' + response.last_name);
  76. document.getElementById('status').innerHTML =
  77. 'Thanks for logging in, ' + response.name + '!';
  78. });
  79. }
  80. </script>
  81.  
  82. <!--
  83. Below we include the Login Button social plugin. This button uses
  84. the JavaScript SDK to present a graphical Login button that triggers
  85. the FB.login() function when clicked.
  86. -->
  87.  
  88. <fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
  89. </fb:login-button>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement