Advertisement
Guest User

Untitled

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