Login to Facebook - PHP

-1

Colleagues, I am trying to insert the LOGIN option through Facebook into my test application (Local Host), however it is displaying the following error:

Mysettingsareasfollows:

and

Ihavealreadymadeseveralchangesandsofarnothing.SeeingsomevideosonYoutube,letmeunderstandthatsincemostofthemhavealreadybeenoutofdate,thentheirsettingsarenotthesame.

HereisthelinkwiththefilesI'musing: link

NOTE: I removed my 'app_id' and 'app_secret' just because it is sharing my file, but the current one is filled in correctly.

Could someone please help me?

    
asked by anonymous 05.01.2018 / 07:05

1 answer

0

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"];
    
08.01.2018 / 05:09