简体   繁体   English

Facebook PHP SDK - 注销问题

[英]Facebook PHP SDK - Logout issue

I am using the FB PHP SDK along with Code Igniter 2 Framework. 我正在使用FB PHP SDK和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. 我的问题是,在使用FB登录后,该页面显示了一个注销链接,在点击时,应将其注销(因此再次显示登录链接)但是它不起作用。

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. 仅仅由于某种原因,FB“会话”仍然存在并且用户仍然使用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? 最后一个小问题 - 我应该使用PHP SDK,还是应该使用Javascript SDK? I cant find any info on which one is best for whatever job?! 我无法找到哪一个最适合任何工作的信息?! Confused.com Confused.com

should I even be using the PHP SDK, or should I use the Javascript SDK? 我应该使用PHP SDK,还是应该使用Javascript SDK?

If your app can be created with the JavaScript SDK instead of the PHP SDK, then go for it. 如果您的应用程序可以使用JavaScript SDK而不是PHP SDK创建,那么请继续使用它。 Save your server's CPU cycles for something else. 保存服务器的CPU周期以获取其他信息。 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). 复杂的应用程序通常同时使用JavaScript SDK和PHP SDK - 在这种情况下,登录通常在Javascript端处理(PHP SDK自动知道用户是否通过JavaScript登录)。

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. 我的问题是,在使用FB登录后,该页面显示了一个注销链接,在点击时,应将其注销(因此再次显示登录链接)但是它不起作用。

This cause by your website cannot clear fb session. 这个原因是你的网站无法清除fb会话。 I have same problem when use facebook api in cakephp framework. 我在cakephp框架中使用facebook api时遇到同样的问题。 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. 我调试并看到,当facebook帐户登录成功时, $this->facebook->user()不为null并且不会抛出任何异常。

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/ 参考: 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);
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM