Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 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.  
  33. window.fbAsyncInit = function() {
  34. FB.init({
  35. appId : '1192154824145063',
  36. cookie : true, // enable cookies to allow the server to access
  37. // the session
  38. xfbml : true, // parse social plugins on this page
  39. version : 'v2.1' // use version 2.1
  40. });
  41.  
  42. };
  43.  
  44. // Load the SDK asynchronously
  45. (function(d, s, id) {
  46. var js, fjs = d.getElementsByTagName(s)[0];
  47. if (d.getElementById(id)) return;
  48. js = d.createElement(s); js.id = id;
  49. js.src = "//connect.facebook.net/en_US/sdk.js";
  50. fjs.parentNode.insertBefore(js, fjs);
  51. }(document, 'script', 'facebook-jssdk'));
  52.  
  53. // Here we run a very simple test of the Graph API after login is
  54. // successful. See statusChangeCallback() for when this call is made.
  55. function testAPI() {
  56. console.log('Welcome! Fetching your information.... ');
  57. FB.api('/me', function(response) {
  58. console.log('Successful login for: ' + response.name);
  59. document.getElementById('status').innerHTML =
  60. 'Thanks for logging in, ' + response.name + '!';
  61. console.log(response);
  62. });
  63. }
  64.  
  65. // fb_login() function for logging in with the custom button
  66. function fb_login () {
  67. FB.getLoginStatus(function(response) {
  68. statusChangeCallback(response);
  69. });
  70. }
  71. </script>
  72.  
  73.  
  74. <button type="button" onclick="fb_login();">login</button>
  75.  
  76. <div id="status">
  77. </div>
  78.  
  79. </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement