Advertisement
ShawnsSpace

asych with DOM profile name and pic write.

Jun 2nd, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <div id="fb-root"></div>
  2. <script>
  3. window.fbAsyncInit = function() {
  4. FB.init({
  5. appId : '142859072412938',
  6. status : true, // check login status
  7. cookie : true, // enable cookies to allow the server to access the session
  8. xfbml : true, // parse XFBML
  9. //channelUrl : '', // channel.html file
  10. oauth : true // enable OAuth 2.0
  11. });
  12. FB.Event.subscribe('auth.login', function(response){
  13. location.reload();
  14. });
  15. FB.Event.subscribe('auth.logout', function(response){
  16. location.reload();
  17. });
  18. FB.getLoginStatus(function(response) {
  19. if (response.status === 'connected') {
  20. // the user is logged in and has authenticated your
  21. // app, and response.authResponse supplies
  22. // the user's ID, a valid access token, a signed
  23. // request, and the time the access token
  24. // and signed request each expire
  25. var uid = response.authResponse.userID;
  26. var accessToken = response.authResponse.accessToken;
  27. FB.api('/me', function(response) {
  28. //alert('Your name is ' + response.name);
  29. var thisusername = '<div id="thename">'+response.name+'</div>';
  30. var thisuserpic = '<div id="image"><img src="'+response.picture+'" id="theimage" /></div>';
  31. var theprofilebox = document.getElementById('user_profile ');
  32. theprofilebox.innerHTML = ''+thisusername+' <br /> '+thisuserpic+'';
  33. });
  34. } else if (response.status === 'not_authorized') {
  35. // the user is logged in to Facebook,
  36. // but has not authenticated your app
  37. } else {
  38. // the user isn't logged in to Facebook.
  39. }
  40. });
  41. };
  42. // Load the SDK Asynchronously
  43. (function(d, s, id) {
  44. var js, fjs = d.getElementsByTagName(s)[0];
  45. if (d.getElementById(id)) return;
  46. js = d.createElement(s); js.id = id;
  47. js.src = "//connect.facebook.net/en_US/all.js";
  48. fjs.parentNode.insertBefore(js, fjs);
  49. }(document, 'script', 'facebook-jssdk'));
  50. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement