Advertisement
diabliyo

fbconnect 25 agosto 2011

Aug 25th, 2011
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. echo '<head>
  2. <script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US"></script>
  3. <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
  4. <script src="http://static.ak.facebook.com/js/api_lib/v0.4/XdCommReceiver.js?2" type="text/javascript"></script>
  5. </head>';
  6.  
  7. # incluimos libreria face
  8. include( "donde/tenemos/facebooklib.php" );
  9.  
  10. $facebook = new Facebook(array(
  11. 'appId' => 'miapiid',
  12. 'secret' => 'misecrethash',
  13. ));
  14.  
  15. $user = $facebook->getUser(); # obtenemos ID del usuario
  16.  
  17. # verificamos si el ID esta conectado a facebook
  18. if( $user )
  19. {
  20. try {
  21. // Proceed knowing you have a logged in user who's authenticated.
  22. $user_profile = $facebook->api('/me');
  23. } catch (FacebookApiException $e) {
  24. error_log($e);
  25. $user = null; # error, no esta conectado a facebook
  26. }
  27. }
  28.  
  29. if ($user) # si esta conectado, creamos LINK de desconexion
  30. $logoutUrl= $facebook->getLogoutUrl();
  31. else # entonces creamos link de conexionsi no esta conectado, le permitimos conectar
  32. $loginUrl= $facebook->getLoginUrl();
  33.  
  34.  
  35. #
  36. # ya en el contenido del sitio web
  37. #
  38.  
  39. if( $user ) # si esta conectado
  40. echo '<a href="'. $logoutUrl. '">Desconectar</a>';
  41. else # invitamos a sincronizar
  42. echo '<div id="fb-root"></div><a href="'. $loginUrl. '"><fb:login-button>Sincronizar </fb:login-button></a>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement