title: Setting up Facebook Login on localhost
body: <p>I've been following the steps outlined here to create a Facebook App Login:
  <a href="http://developers.facebook.com/docs/howtos/login/server-side-login/" rel="nofollow noreferrer">http://developers.facebook.com/docs/howtos/login/server-side-login/</a></p>
  
  <p>And am on Step 3.  I'm setting this up on localhost for development and then I'll publish to Azure Websites with a different App ID.  I'd like to have this working on localhost first though.  (I haven't tried this with a non-localhost domain yet.)</p>
  
  <p>On my Facebook App configuration page I've set a couple relevant fields:
  Site URL: http:// localhost : 8052/  (Spaces added to allow submision to Stack Overflow)
  App Domains: localhost</p>
  
  <p>main.php redirects to a login page if there is no Facebook code set.  This works fine.</p>
  
  <pre><code>&lt;head&gt;
  &lt;?php
     if(!isset($_SESSION['code'])) {
        echo ('&lt;meta http-equiv="REFRESH" content="0;url=/login.php" /&gt;');
     }
  ?&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>login.php redirects to Facebook's login page using code copied from their example.</p>
  
  <pre><code>&lt;?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 . "&amp;redirect_uri=" . urlencode($my_url) . "&amp;state="
         . $_SESSION['state'];
  
       echo $my_url.'&lt;br/&gt;';
       echo $dialog_url.'&lt;br/&gt;';
       echo("&lt;script&gt; top.location.href='" . $dialog_url . "'&lt;/script&gt;");
     }
  ?&gt;  
  </code></pre>
  
  <p>Clearly I've obfuscated my App ID above.</p>
  
  <p>The URL generated by my "CreateUrlForPage" function looks fine as does the facebook login URL:</p>
  
  <pre><code>http://localhost:8052/welcome.php
  https://www.facebook.com/dialog/oauth?client_id=XXXX&amp;redirect_uri=http%3A%2F%2Flocalhost%3A8052%2Fwelcome.php&amp;state=XXXX
  </code></pre>
  
  <p>(Again, some obfuscation here.  The real values looked okay.  The first being an integer the second being a long hex string.)</p>
  
  <p>When I navigate to http:// localhost : 8052/login.php, The page redirects to Facebook and gives a completely useless error: "An error occurred.  Please try again later."</p>
  
  <p>I looked at a couple other posts on Stack Overflow, but they didn't solve my problem.  </p>
  
  <p>The error I'm getting looks just like the one described here:
  <a href="https://stackoverflow.com/questions/9654396/facebook-application-login-error-on-localhost">Facebook application login error on localhost </a>
  The suggestion provided is to set the Domain and Site URL, which I've done.</p>
  
  <p>There is also a link to this question: <a href="https://stackoverflow.com/questions/5133075/running-facebook-application-on-localhost">Running Facebook application on localhost</a>
  Again, they suggest Site URL.  They also talk about app-canvas which is not something I'm using and I don't see how it would be related to login.  </p>
  
  <p>For what it's worth, before I set the Site URL and Domain, I was getting a different error - one that told me I needed to set the Site URL.</p>