/src/main/webapp/fb/examples/mootools/login.html

https://github.com/arindambiswas/NatGeo · HTML · 84 lines · 60 code · 9 blank · 15 comment · 0 complexity · b9b56d68d8229f358dc00f28bdcddd0d MD5 · raw file

  1. <!doctype html>
  2. <html>
  3. <!--
  4. Copyright Facebook Inc.
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <head>
  16. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  17. <title>Connect JavaScript - MooTools Login Example</title>
  18. </head>
  19. <body>
  20. <h1>Connect JavaScript - MooTools Login Example</h1>
  21. <div>
  22. <button id="login">Login</button>
  23. <button id="logout">Logout</button>
  24. <button id="disconnect">Disconnect</button>
  25. </div>
  26. <div id="user-info"></div>
  27. <script src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.3/mootools-yui-compressed.js"></script>
  28. <div id="fb-root"></div>
  29. <script src="http://connect.facebook.net/en_US/all.js"></script>
  30. <script>
  31. // initialize the library with the API key
  32. FB.init({ apiKey: '48f06bc570aaf9ed454699ec4fe416df' });
  33. // fetch the status on load
  34. FB.getLoginStatus(handleSessionResponse);
  35. $('login').addEvent('click', function() {
  36. FB.login(handleSessionResponse);
  37. });
  38. $('logout').addEvent('click', function() {
  39. FB.logout(handleSessionResponse);
  40. });
  41. $('disconnect').addEvent('click', function() {
  42. FB.api({ method: 'Auth.revokeAuthorization' }, function(response) {
  43. clearDisplay();
  44. });
  45. });
  46. // no user, clear display
  47. function clearDisplay() {
  48. document.getElementById('user-info').innerHTML = '';
  49. }
  50. // handle a session response from any of the auth related calls
  51. function handleSessionResponse(response) {
  52. // if we dont have a session, just hide the user info
  53. if (!response.session) {
  54. clearDisplay();
  55. return;
  56. }
  57. // if we have a session, query for the user's profile picture and name
  58. FB.api(
  59. {
  60. method: 'fql.query',
  61. query: 'SELECT name, pic FROM profile WHERE id=' + FB.getSession().uid
  62. },
  63. function(response) {
  64. var user = response[0];
  65. var userInfo = document.getElementById('user-info');
  66. userInfo.innerHTML = '<img src="' + user.pic + '">' + user.name;
  67. }
  68. );
  69. }
  70. </script>
  71. </body>
  72. </html>