Facebook login setup on localhost

I followed the steps described here to create a Facebook login: http://developers.facebook.com/docs/howtos/login/server-side-login/

And I'm in step 3. I configure this on the local host for development, and then I publish to Azure websites with a different application identifier. However, I would like this to work on localhost. (I have not tried this with a non-localhost domain yet.)

On my Facebook application configuration page, I set a couple of relevant fields: Site URL: http: // localhost: 8052 / (Spaces added to allow stack overflow) Application domains: localhost

main.php redirects the login page if there is no Facebook code. It works great.

<head> <?php if(!isset($_SESSION['code'])) { echo ('<meta http-equiv="REFRESH" content="0;url=/login.php" />'); } ?> </head> 

login.php redirects to the Facebook login page using code copied from their example.

 <?php include '/lib/url.php'; $app_id = "XXXXX"; $app_secret = "XXXXX"; $my_url = CreateUrlForPage('welcome.php'); session_start(); $code = ''; if(!isset($_REQUEST["code"])) { $_SESSION['state'] = md5(uniqid(rand(), TRUE)); // CSRF protection $dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state=" . $_SESSION['state']; echo $my_url.'<br/>'; echo $dialog_url.'<br/>'; echo("<script> top.location.href='" . $dialog_url . "'</script>"); } ?> 

Obviously, I obfuscated my app id above.

The URL generated by my CreateUrlForPage function looks just as good as the facebook login address:

 http://localhost:8052/welcome.php https://www.facebook.com/dialog/oauth?client_id=XXXX&redirect_uri=http%3A%2F%2Flocalhost%3A8052%2Fwelcome.php&state=XXXX 

(Again, some obfuscations are here. The real values โ€‹โ€‹looked good. The first is an integer, the second is a long hexadecimal string.)

When I go to http: // localhost: 8052 / login.php, the page redirects to Facebook and gives an absolutely useless error: "An error has occurred. Please try again later."

I looked at a couple of stack overflow messages, but they did not solve my problem.

The error that I get looks like the one described here: Error logging into the Facebook application on the local host The suggested suggestion is to set the URL of the domain and the site I made.

There is also a link to this question: Launching a Facebook application on a local host Again, they offer a website URL. They also talk about a canvas application, which is not what I use, and I donโ€™t see how this will be associated with the login.

What is it worth? Before I set the URL and domain of the site, I had another error: one that told me that I needed to set the URL of the site.

+4
php facebook localhost facebook-apps facebook-login
source share
1 answer

this code worked for me. double check your facebook app id and the URL of my site is set to http: // localhost: 8052 / no need to set a domain name for login.

http://gamma.owlweb.com.ua/index.php/?route=account/register/fb

 <?php $app_id = "xxx"; $app_secret = "xxx"; $my_url ="http://localhost:3080/abc.php"; session_start(); $code = ''; if(!isset($_REQUEST["code"])) { $_SESSION['state'] = md5(uniqid(rand(), TRUE)); // CSRF protection $dialog_url = "https://www.facebook.com/dialog/oauth?client_id=".$app_id ."&redirect_uri=".urlencode($my_url) ."&state=".$_SESSION['state']; echo $my_url.'<br/>'; echo $dialog_url.'<br/>'; echo("<script> top.location.href='" . $dialog_url . "'</script>"); } ?> 
+2
source share

All Articles