Facebook Login localhost

Asked

Viewed 1,503 times

-2

Ajax Facebook Connect with jQuery & PHP

I can’t run Facebook on the local machine. I want to implement Login with Facebook on my site more I would like to test locally above this login I am trying to implement!

  • Yes, you need a powerful machine to run facebook on the local machine... Joking aside, what is the problem you are having?

  • The problem is that I want to test "Login with Facebook" on the local machine (Localhost) and then implement on my site that is not yet hosted

  • The problem is you want to test? :)

  • No, more like entering my site than it is on the local server

  • Your local server runs PHP?

  • Yes, it works very well!

  • Test the code below on it then, which should work normally. If there is an error, then you warn.

Show 2 more comments

2 answers

1

Here is a very simplified example of how to use the facebook API for PHP, which is here:

<?php
   require '../src/facebook.php';
   $facebook = new Facebook( array(
      'appId'  => 'PONHA SEU APPID AQUI',
      'secret' => 'PONHA SEU TOKEN AQUI',
   ));

   $user = $facebook->getUser();
   if ($user) {
      try {
         $user_profile = $facebook->api('/me');
      } catch (FacebookApiException $fberror) {
         error_log($fberror);
         $user = null;
      }

      $link = $facebook->getLogoutUrl();
   } else {
      $link = $facebook->getLoginUrl();
   }
?>
<!doctype html>
<html>
   <body>
<?php if ($user) { ?>
      <a href="<?php echo $link; ?>">Logout</a>
<?php } else { ?>
      <a href="<?php echo $link; ?>">Login com Facebook</a>
<?php } ?>

<?php if ($user) {  ?>
      <h3>Voce:</h3>
      <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
      <h3>Perfil:</h3>
      <pre><?php print_r($user_profile); ?></pre>
<?php } else {?>
      <h3>Erro:</h3>
      <?php echo $fberror; ?>
<?php } ?>
   </body>
</html>

Test on your machine with your ID and TOKEN, and let us know if you are experiencing any errors.

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.