As I said in the question comments, you should use the same url (literally) as the Valid OAuth redirect URIs when call the getLoginUrl method
- If you use link in one URL, you should use the other
- If you do not www in one URL, you should not use
- If you use a facebook-callback.php file in one url, you should use it in the other;
- Do not use similar URL, use the same.
If you use link in the getLoginUrl
method, you should use link in configuration URIs de redirecionamento do OAuth válidos
If you put a character more or less, it goes wrong.
PHP:
session_start();
require "vendor/autoload.php";
$fb = new Facebook\Facebook([
'app_id' => 'APP_ID',
'app_secret' => 'APP_SECRET',
'default_graph_version' => 'v2.2',
]);
$helper = $fb->getRedirectLoginHelper();
echo $helper->getLoginUrl("https://www.meu-site-de-exemplo.com/facebook-callback.php", ["email"]);
Configuration:
GeneratedURL:
https://www.facebook.com/v2.2/dialog/oauth?client_id=<CLIENT_ID>&state=<STATE>&response_type=code&sdk=php-sdk-5.6.1&redirect_uri=https%3A%2F%2Fwww.meu-site-de-exemplo.com%2Ffacebook-callback.php&scope=email
GeneratedURLResult:
facebook-callback.php
session_start();require"vendor/autoload.php";
$fb = new Facebook\Facebook([
'app_id' => 'APP_ID',
'app_secret' => 'APP_SECRET',
'default_graph_version' => 'v2.2',
]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
Capturing User Data:
$me = $fb->get("/me?fields=id,name,email", $accessToken);
$user = $me->getGraphUser();
echo $user["email"];