Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. <%@ page language="java" contentType="text/html; utf-8"
  2. pageEncoding="utf-8"%>
  3. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  4. <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
  5. <script>
  6. // This is called with the results from from FB.getLoginStatus().
  7. function statusChangeCallback(response) {
  8. console.log('statusChangeCallback');
  9. console.log(response);
  10. console.log(response.authResponse.accessToken);
  11. // The response object is returned with a status field that lets the
  12. // app know the current login status of the person.
  13. // Full docs on the response object can be found in the documentation
  14. // for FB.getLoginStatus().
  15. if (response.status === 'connected') {
  16. // Logged into your app and Facebook.
  17. testAPI();
  18.  
  19. } else {
  20. // The person is not logged into your app or we are unable to tell.
  21. document.getElementById('status').innerHTML = 'Please log ' +
  22. 'into this app.';
  23. }
  24. }
  25.  
  26. // This function is called when someone finishes with the Login
  27. // Button. See the onlogin handler attached to it in the sample
  28. // code below.
  29. function checkLoginState() {
  30. FB.getLoginStatus(function(response) {
  31. statusChangeCallback(response);
  32. });
  33. }
  34.  
  35. window.fbAsyncInit = function() {
  36. FB.init({
  37. appId : '458401588296412',
  38. cookie : true, // enable cookies to allow the server to access
  39. // the session
  40. xfbml : true, // parse social plugins on this page
  41. version : 'v3.3' // The Graph API version to use for the call
  42. });
  43.  
  44. // Now that we've initialized the JavaScript SDK, we call
  45. // FB.getLoginStatus(). This function gets the state of the
  46. // person visiting this page and can return one of three states to
  47. // the callback you provide. They can be:
  48. //
  49. // 1. Logged into your app ('connected')
  50. // 2. Logged into Facebook, but not your app ('not_authorized')
  51. // 3. Not logged into Facebook and can't tell if they are logged into
  52. // your app or not.
  53. //
  54. // These three cases are handled in the callback function.
  55.  
  56. FB.getLoginStatus(function(response) {
  57. statusChangeCallback(response);
  58. });
  59.  
  60. };
  61.  
  62. // Load the SDK asynchronously
  63. (function(d, s, id) {
  64. var js, fjs = d.getElementsByTagName(s)[0];
  65. if (d.getElementById(id)) return;
  66. js = d.createElement(s); js.id = id;
  67. js.src = "https://connect.facebook.net/en_US/sdk.js";
  68. fjs.parentNode.insertBefore(js, fjs);
  69. }(document, 'script', 'facebook-jssdk'));
  70.  
  71. // Here we run a very simple test of the Graph API after login is
  72. // successful. See statusChangeCallback() for when this call is made.
  73. function testAPI() {
  74. console.log('Welcome! Fetching your information.... ');
  75. FB.api('/me', function(response) {
  76. console.log('Successful login for: ' + response.name);
  77. document.getElementById('status').innerHTML =
  78. 'Thanks for logging in, ' + response.name + '!';
  79. });
  80. }
  81. function fbLogout() {
  82. FB.logout(function (response) {
  83. //Do what ever you want here when logged out like reloading the page
  84. window.location.reload();
  85. });
  86. }
  87.  
  88.  
  89. function continueWithFb()
  90. {
  91. FB.getLoginStatus(function(response) {
  92. window.location.href='http://localhost:8080/OnlineShop/LoginFbServlet?access_token=' + response.authResponse.accessToken;
  93. console.log(response.authResponse.accessToken);
  94. });
  95.  
  96. /// window.location.href='LoginFbServlet?access_token='+response.authResponse.accessToken;
  97. }
  98. </script>
  99.  
  100. <!--
  101. Below we include the Login Button social plugin. This button uses
  102. the JavaScript SDK to present a graphical Login button that triggers
  103. the FB.login() function when clicked.
  104. -->
  105.  
  106. <fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
  107. </fb:login-button>
  108. <button onclick="continueWithFb()">Kontynuuj zakupy</button>
  109. <span id="fbLogout" onclick="fbLogout()"><a class="fb_button fb_button_medium"><span class="fb_button_text">Logout</span></a></span>
  110. <div id="status">
  111. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement