Facebook Authorization runs in to a redirect loop
-
26-10-2019 - |
Question
I am using the Facebook app canvas code in the documentation and it keeps redirecting after I hit "allow". Not sure what is wrong. Do check if it is a bug or it is just me. Its from http://developers.facebook.com/docs/appsonfacebook/tutorial/
<?php
$app_id = ""; //Added my app id
$canvas_page = ""; //Added my canvas page
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page);
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
echo ("Welcome User: " . $data["user_id"]);
}
?>
Solution
my recommend is using php Sdk it makes every thing easier for you & the code for login will be like this :
<?php
include_once('src/facebook.php');
$config = array(
'appId' => 'xxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxx',
'fileUpload' => FALSE, // optional
);
$canvas_page = ""; //Added my canvas page
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page);
$uid=$facebook->getuser();
if(empty($uid)){ echo("<script> top.location.href='" . $auth_url . "'</script>");}
else { echo ("Welcome User: " . $uid);}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow