Facebook SDK PHP login "Bad Request"
<p>I am trying to create FB login with PHP.
The URL of my App is : http:// example.com.
The redirect URL is http:// example.com/login/facebook/</p>

<p>This is my code for creating login URL in http:// example.com:</p>

<pre><code>    $fb = new \Facebook\Facebook([
        'app_id'     =&gt; FB_APP_ID,
        'app_secret' =&gt; FB_APP_SECRET,
        'default_graph_version' =&gt; 'v2.2',
    ]);

    $callback = 'http:// example.com/login/facebook/';
    $helper = $fb-&gt;getRedirectLoginHelper();
    $permissions = ['email'];
    $data['fb_url'] = $helper-&gt;getLoginUrl($callback, $permissions);
</code></pre>

<p>I get an URL and set it to a link where user can click and login.</p>

<p>This is my code in redirect URL (http:// example.com/login/facebook/):</p>

<pre><code>    $fb = new Facebook\Facebook([
        'app_id' =&gt; FB_APP_ID, // Replace {app-id} with your app id
        'app_secret' =&gt; FB_APP_SECRET,
        'default_graph_version' =&gt; 'v2.2',
    ]);

    $helper = $fb-&gt;getRedirectLoginHelper();

    try {
        $accessToken = $helper-&gt;getAccessToken();
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
        // When Graph returns an error
        echo 'Graph returned an error: ' . $e-&gt;getMessage();
        exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo 'Facebook SDK returned an error: ' . $e-&gt;getMessage();
        exit;
    }

    if (! isset($accessToken)) {
        if ($helper-&gt;getError()) {
            header('HTTP/1.0 401 Unauthorized');
            echo "Error: " . $helper-&gt;getError() . "\n";
            echo "Error Code: " . $helper-&gt;getErrorCode() . "\n";
            echo "Error Reason: " . $helper-&gt;getErrorReason() . "\n";
            echo "Error Description: " . $helper-&gt;getErrorDescription() . "\n";
        } else {
            header('HTTP/1.0 400 Bad Request');
            echo 'Bad request';
        }
        exit;
    }
</code></pre>

<p>The code is from the example here - <a href="https://developers.facebook.com/docs/php/howto/example_facebook_login" rel="nofollow">FB SDK DOCS</a> ,
but I get this error:</p>

<blockquote>
  <p>Bad request</p>
</blockquote>

<p>and access token = NULL. 
Where is the error and how to fix ?</p>