Facebook PHP SDK - 注销问题

发布于 2025-01-08 19:40:08 字数 1215 浏览 0 评论 0原文

我正在使用 FB PHP SDK 和 Code Igniter 2 框架。

我有一个注册页面,可以在其中显示一个链接,供用户单击并批准该应用程序,并授予其访问其基本数据和电子邮件的权限。这似乎工作正常(虽然我已将其设置为弹出窗口,但它不会弹出,它只是显示在同一页面中!)。

我的问题是,使用 FB 登录后,页面显示一个注销链接,单击该链接后,应该将其注销(因此再次显示登录链接),但它不起作用。

我设置了一个参数来将其页面转到某个页面,这确实有效。出于某种原因,FB“会话”会保留下来,并且用户会保持 FB 登录状态。

有什么想法吗?

我的控制器中的代码:

// Facebook Connect
    $fb_config = array(
        'appId'  => 'xxx',
        'secret' => 'xxx'   
    );

    $this->load->library('facebook', $fb_config);

    $user = $this->facebook->getUser();

    if ($user) {
        try {
            $data['user_profile'] = $this->facebook->api('/me');
        } catch (FacebookApiException $e) {
            $user = null;
        }
    }

    if ($user) {
        $params = array('next' => 'http://localhost/game/index.php/game/login');
        $data['logout_url'] = $this->facebook->getLogoutUrl($params);
    } else {
        $params = array('scope' => 'email, publish_stream, publish_actions', 'display' => 'popup');
        $data['login_url'] = $this->facebook->getLoginUrl($params);
    }

最后一个小问题 - 我应该使用 PHP SDK,还是应该使用 Javascript SDK?我找不到任何关于哪一个最适合任何工作的信息?!困惑网

I am using the FB PHP SDK along with Code Igniter 2 Framework.

I have a registration page where I can display a link for the user to click and approve the app and give it access to their basic data and email. This seems to work fine (although I have set it to be a popup, it doesn't popup, it just shows in the same page!).

My problem is that after being logged in with FB, the page shows a logout link, which when click, should log them out (and therefore show the login link again) BUT it doesn't work.

I have a parameter set to take it page to a certain page, and that does work. Just for some reason the FB "session" stick around and the user stays logged in with FB.

Any ideas?

my code in my controller:

// Facebook Connect
    $fb_config = array(
        'appId'  => 'xxx',
        'secret' => 'xxx'   
    );

    $this->load->library('facebook', $fb_config);

    $user = $this->facebook->getUser();

    if ($user) {
        try {
            $data['user_profile'] = $this->facebook->api('/me');
        } catch (FacebookApiException $e) {
            $user = null;
        }
    }

    if ($user) {
        $params = array('next' => 'http://localhost/game/index.php/game/login');
        $data['logout_url'] = $this->facebook->getLogoutUrl($params);
    } else {
        $params = array('scope' => 'email, publish_stream, publish_actions', 'display' => 'popup');
        $data['login_url'] = $this->facebook->getLoginUrl($params);
    }

Last little question - should I even be using the PHP SDK, or should I use the Javascript SDK? I cant find any info on which one is best for whatever job?! Confused.com

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

零度℉ 2025-01-15 19:40:08

我应该使用 PHP SDK,还是应该使用 Javascript SDK?

如果您的应用程序可以使用 JavaScript SDK 而不是 PHP SDK 创建,那么就使用它。节省服务器的 CPU 周期以用于其他用途。它还允许您异步执行登录,这很好。

复杂的应用程序通常同时使用 JavaScript SDK 和 PHP SDK——在这种情况下,登录通常在 Javascript 端处理(PHP SDK 自动知道用户是否通过 JavaScript 登录)。

should I even be using the PHP SDK, or should I use the Javascript SDK?

If your app can be created with the JavaScript SDK instead of the PHP SDK, then go for it. Save your server's CPU cycles for something else. It also allows you to perform login asynchronously which can be nice.

Complex apps usually use both the JavaScript SDK and the PHP SDK -- in which case login is often handled on the Javascript side (the PHP SDK automatically knows if the user logged in via JavaScript).

陌若浮生 2025-01-15 19:40:08

我的问题是用FB登录后,页面显示
注销链接,单击该链接后,应将其注销(因此显示
再次登录链接)但它不起作用。

这是由于您的网站无法清除fb会话造成的。在 cakephp 框架中使用 facebook api 时我遇到同样的问题。而且......我尝试在用户注销时清除会话(我不喜欢它)。
我调试并看到,当 facebook 帐户登录成功时,$this->facebook->user() 不为 null 并且没有抛出任何异常。

My problem is that after being logged in with FB, the page shows a
logout link, which when click, should log them out (and therefore show
the login link again) BUT it doesn't work.

This cause by your website cannot clear fb session. I have same problem when use facebook api in cakephp framework. And ... I try to clear session when user logout (I don't like it).
I debug and see that when facebook account login successful,$this->facebook->user() not null and throw no exception.

泼猴你往哪里跑 2025-01-15 19:40:08

您需要将活动用户访问令牌添加到注销链接才能使注销链接正常工作。

参考:https://developers.facebook.com/docs/reference/php /facebook-getLogoutUrl/

示例:

if ($user) {
  $params = array (
  access_token => ''.$access_token.'',
  );
  $logoutUrl = $facebook->getLogoutUrl($params);
} else {
$params = array(
  scope => 'read_stream,publish_stream,publish_actions,read_friendlists',
  //redirect_uri => $url
  );
  $loginUrl = $facebook->getLoginUrl($params);
};

You need to have an active user access token added to the logout link for the logout link to work.

refer to: https://developers.facebook.com/docs/reference/php/facebook-getLogoutUrl/

example:

if ($user) {
  $params = array (
  access_token => ''.$access_token.'',
  );
  $logoutUrl = $facebook->getLogoutUrl($params);
} else {
$params = array(
  scope => 'read_stream,publish_stream,publish_actions,read_friendlists',
  //redirect_uri => $url
  );
  $loginUrl = $facebook->getLoginUrl($params);
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文