拒绝 Facebook 身份验证
我制作了一个应用程序,允许用户使用他们的 Facebook 帐户登录。当被问及是否要授予我的应用程序从他们的 Facebook 帐户访问某些详细信息的权限时,如果他们单击“允许”,一切都会正常。然而,当他们单击“拒绝”时,它只会继续循环并不断询问他们是否要授予应用程序权限。当他们单击“拒绝”时,如何让它转到另一个页面,而不是不断循环并询问相同的问题?
我尝试查看文档,但似乎找不到我想要的内容。
在请求许可之前,执行以下操作,然后如果我单击“不允许”,它只会继续循环下面的代码,直到我单击“允许”:
<?php
session_start();
require("facebook.php");
$facebook = new Facebook(array(
'appId' => 'app id goes here',
'secret' => 'secret goes here',
'cookie' => true
));
$session = $facebook->getSession();
if(!empty($session)) {
try{
$uid = $facebook->getUser();
$user = $facebook->api('/me');
$_SESSION['returned'] = array("id" => $uid, "name" => $user["name"], "access_token" => $session['access_token']);
header('Location: returned.php');
exit;
} catch (Exception $e) {
echo "something is wrong";
exit;
}
} else {
$login_url = $facebook->getLoginUrl();
header("Location: ".$login_url);
}
I have made an application which allows a user to login using their facebook account. Everything works find if they click "allow" when asked if they want give my application permission to access certain details from their facebook account. However, when they click "deny", it just keeps looping and keeps asking them if they want to give permission to the application. How do I get it to go to another page when they click "deny" instead of it continously looping and asking the same question?
I've tried looking at the documentation, but can't seem to find what I'm after.
Before asking for permission, the following is executed, then if I click "don't allow", it just keeps looping through the code below until I click "allow":
<?php
session_start();
require("facebook.php");
$facebook = new Facebook(array(
'appId' => 'app id goes here',
'secret' => 'secret goes here',
'cookie' => true
));
$session = $facebook->getSession();
if(!empty($session)) {
try{
$uid = $facebook->getUser();
$user = $facebook->api('/me');
$_SESSION['returned'] = array("id" => $uid, "name" => $user["name"], "access_token" => $session['access_token']);
header('Location: returned.php');
exit;
} catch (Exception $e) {
echo "something is wrong";
exit;
}
} else {
$login_url = $facebook->getLoginUrl();
header("Location: ".$login_url);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 api 它将把用户重定向到您提供的页面: http://YOUR_URL?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request。
在您重定向的页面中检查 url 参数“错误”
此外,成功后应该有一个 url 参数“代码”,您应该在继续之前验证该参数是否存在
according to the api it will redirect the user to the page you provided: http://YOUR_URL?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.
In the page you redirect to check for url parameter "error"
In addition on success there should be a url parameter "code" which you should verify exists before proceeding