拒绝 Facebook 身份验证

发布于 2024-12-12 03:54:35 字数 1021 浏览 0 评论 0原文

我制作了一个应用程序,允许用户使用他们的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み青杉依旧 2024-12-19 03:54:35

根据 api 它将把用户重定向到您提供的页面: http://YOUR_URL?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request

在您重定向的页面中检查 url 参数“错误”
此外,成功后应该有一个 url 参数“代码”,您应该在继续之前验证该参数是否存在

if (isset($_GET['error'])) {
  header('Location: URL_TO_GO_IF_FAILED');
} else {
  // ... whatever you were doing before
}

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

if (isset($_GET['error'])) {
  header('Location: URL_TO_GO_IF_FAILED');
} else {
  // ... whatever you were doing before
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文