App keeps asking for "allow permission" even thought I did it.
I'm visiting this link after the first time of allowing the permission, and I'm confused. Shouldn't the second time or third, just send me to the redirect link and not asking me again for the permission that I've allowed already?
When I click log in with Facebook, it ask to authorize already authorized user. I am using PHP SDK 5.7.0. I got this problem when I migrated my site to another host, but however I don't believe that this is the main problem.
NOTE: If the code is asking JUST for "email" permission and no other permission, it works perfectly. config-fb.php
if(!isset($_SESSION))
session_start();
require_once "Facebook/autoload.php";
$FB = new \Facebook\Facebook([
'app_id' => '{APP_ID}',
'app_secret' => '{APP_SECRET}',
'default_graph_version' => 'v3.3'
]);
$helper = $FB->getRedirectLoginHelper();
$permissions = ['email', 'manage_pages']; //if there is only the email permission, it works perfectly
$redirectURL = "http://localhost/fb-callback.php";
$loginURL = $helper->getLoginUrl($redirectURL, $permissions);
echo "<a href='".$loginURL."'>Login</a>";
fb-callback.php
<?php
require_once "config-fb.php";
if (isset($_GET['state'])) {
$helper->getPersistentDataHandler()->set('state', $_GET['state']);
}
try {
$accessToken = $helper->getAccessToken();
} catch (\Facebook\Exceptions\FacebookResponseException $e) {
echo "Response Exception: " . $e->getMessage();
exit();
} catch (\Facebook\Exceptions\FacebookSDKException $e) {
echo "SDK Exception: " . $e->getMessage();
exit();
}
if (!$accessToken) {
echo "Access token missing";
exit();
}
$oAuth2Client = $FB->getOAuth2Client();
if (!$accessToken->isLongLived())
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
$response = $FB->get("/me?fields=id, accounts{id,name,picture,access_token}, first_name, last_name, email, picture.type(large)", $accessToken);
$userData = $response->getGraphNode()->asArray();
if(!isset($_SESSION)){
session_start();
}
echo "Good";
//Then do something with $accessToken;