Facebook Login localhost

-2

Ajax Facebook Connect with jQuery & PHP

I can not run facebook on the local machine. I want to implement Login with Facebook on my site but I would like to test locally above the login I am trying to implement!

    
asked by anonymous 22.09.2014 / 12:14

2 answers

1

Here's 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/<?phpecho$user;?>/picture">
      <h3>Perfil:</h3>
      <pre><?php print_r($user_profile); ?></pre>
<?php } else {?>
      <h3>Erro:</h3>
      <?php echo $fberror; ?>
<?php } ?>
   </body>
</html>

Test your machine with your ID and your TOKEN, and let me know if you're having any errors.

    
22.09.2014 / 12:43
0

Friend, you will need to create an alias for your project. Today you are accessing so localhost / yourupproject. In this way Facebook can not understand, you will need to create an alias for your project, leaving the access to it so local.seuprojeto.com.br. To do this, take a look at this post: link

I hope I have helped.

    
23.03.2015 / 14:57