Facebook API - 用户注销后会话仍然存在

发布于 2024-10-08 19:35:21 字数 855 浏览 2 评论 0原文

我在我的 iframe facebook 应用程序中使用 Facebook php-sdk 来获取用户登录状态。 在我使用 facebook 帐户注销后 >注销链接,会话尚未销毁。我必须在旧会话过期之前等待几分钟,然后我的应用程序将再次获得正确的登录状态。

我希望当用户退出时 Facebook 会自行终止并终止会话。如何手动终止会话?

这是我的代码:

$initParams = array(
  'appId'  => $conf['app_id'], 
  'secret' => $conf['secret_api_key'],
  'cookie' => TRUE,
);

$fb = new Facebook($initParams);
$fb->getSession();  // will return a session object eventhough user signed out!

已解决:

如果用户之前已注销,调用$fb->api('/me')将破坏会话。 我已将代码更改如下:

if ($session)
{
    try
    {
        $fbuid = $fb->getUser();
        $me = $fb->api('/me');
    }
    catch(FacebookApiException $e){}
}

如果 API 调用不成功,$session 将设置为 NULL。非常奇怪的行为,我没有解释这里发生的所有事情,但它解决了我的剩余会话对象未通过 getSession() 方法更新的问题。

I am using Facebook php-sdk in my iframe facebook app to get user login status.
Right after I sign out using facebook Account > Log out link, the session is not destroyed yet. I must wait a few minutes before old session expires, then my app will again get the correct login status.

I expect the facebook to kill itself and the session when user signs out. How do I manually kill the session?

Here is my code:

$initParams = array(
  'appId'  => $conf['app_id'], 
  'secret' => $conf['secret_api_key'],
  'cookie' => TRUE,
);

$fb = new Facebook($initParams);
$fb->getSession();  // will return a session object eventhough user signed out!

SOLVED:

calling $fb->api('/me') will destroy the session if user has previously logged out.
I've changed my code as following:

if ($session)
{
    try
    {
        $fbuid = $fb->getUser();
        $me = $fb->api('/me');
    }
    catch(FacebookApiException $e){}
}

If the API call is unsuccessful, $session will be set to NULL. Very weird behavior, I don't explain everything that is going on here but it solved my problem of having residual session object not being updated via getSession() method.

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

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

发布评论

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

评论(7

隔岸观火 2024-10-15 19:35:21

我正在使用 $fb->getUser() ,我所做的与你的几乎相同。

if ($fb->getUser())
{
    try
    {
        $me = $fb->api('/me');
    }
    catch(FacebookApiException $e){
        **$fb->destroySession();**
    }
}

我发现仅使用API​​来检查FB是否已注销有时会不一致,但使用destroySession(),会话肯定会被销毁。

I'm using $fb->getUser() and what I did was almost identical with yours.

if ($fb->getUser())
{
    try
    {
        $me = $fb->api('/me');
    }
    catch(FacebookApiException $e){
        **$fb->destroySession();**
    }
}

I found that using only API to check whether FB is logged out or not sometimes is inconsistent, but with destroySession(), the session will surely be destroyed.

¢蛋碎的人ぎ生 2024-10-15 19:35:21

如果您在登录页面上使用 javascript FB.INIT 调用,则将状态从 true 设置为 false。

有关状态属性的详细信息:
http://developers.facebook.com/docs/reference/javascript/FB。初始化/

if you are using the javascript FB.INIT calls on the login page, then set status to false from true.

details about the status attribute :
http://developers.facebook.com/docs/reference/javascript/FB.init/

陪你搞怪i 2024-10-15 19:35:21

尝试在 LoginWindow (AS3) 的某处找到 formatData 函数并找到这一行:

vars.redirect_uri = FacebookURLDefaults.LOGIN_SUCCESS_URL

更改 http://www.facebook.com/ 的值并在登录时从该 html 页面注销。

这是如果您是开发人员而不是最终用户,则可以使用临时注销解决方案。

Try finding the formatData function somewhere at LoginWindow (AS3) and find this line:

vars.redirect_uri = FacebookURLDefaults.LOGIN_SUCCESS_URL

Change the value for http://www.facebook.com/ and logout from that html page when logged in.

This is a temporary solution to logout if you are developer, not the end user.

ぺ禁宫浮华殁 2024-10-15 19:35:21

Facebook 应取消会话与会话所属帐户的关联。您可以使用 Facebook::getUser() 检查是否已完成此操作:

if ($fb->getUser() === null) {
  // User logged out
} else {
  // User logged in
}

Facebook should disassociate the session from the account that the session belonged to. You can use Facebook::getUser() to check whether this was done:

if ($fb->getUser() === null) {
  // User logged out
} else {
  // User logged in
}
末蓝 2024-10-15 19:35:21

尝试 $facebook->setSession(null) 或使用 javascript Logout;

Try $facebook->setSession(null) or using javascript <a href="/logout/" onclick="FB.logout();">Logout</a>

别低头,皇冠会掉 2024-10-15 19:35:21

注销无论如何都不起作用。

登录 Facebook 后,尝试在浏览器中发布此链接。

https://www.facebook.com/logout.php

发生了什么?它会带你到你的脸书。根本没有注销。

无论您做什么,请检查函数(取决于您的 API)handleLogout 并检查输出。就我而言,它返回整个 facebook html 页面。

Logout does not work any way you do.

Try posting this link in your browser, after you log in to facebook.

https://www.facebook.com/logout.php

What happen? it takes you to your facebook. No logout at all.

What ever you do, check the function (depends on your API) handleLogout and check the output. In my case, it returns the entire facebook html page.

一个人的旅程 2024-10-15 19:35:21

我设法解决此问题的唯一方法是使用签名请求检查用户 ID 来清除会话:

$facebook = Membership::getFacebookApp();
$signed_request = $facebook->getSignedRequest();
if(isset($_SESSION['facebook_id']) && $signed_request['user_id'] != (int)$_SESSION['facebook_id']){
    $_SESSION = array();
}

The only way I've managed to solve this problem was by clearing the session using the signed request to check the user id:

$facebook = Membership::getFacebookApp();
$signed_request = $facebook->getSignedRequest();
if(isset($_SESSION['facebook_id']) && $signed_request['user_id'] != (int)$_SESSION['facebook_id']){
    $_SESSION = array();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文