Facebook getUser() 函数在注销后返回用户 ID
我正在使用 Facebook PHP SDK 进行开发。
我想做到这一点,当用户退出 Facebook 时,他们也会自动退出我的网站。
我使用以下代码来检测会话,并使用会话 cookie:
$facebook->getUser();
由于某种原因,getUser()
函数仍然返回用户的 Facebook ID,即使用户已在其网站上退出 Facebook 。
我是否要首先使用另一个函数检测会话?
在官方文档示例此处,如下摘自他们的评论:
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
这让我相信 Facebook 的会话 cookie 会在 Facebook 注销时取消设置?
亲切的问候,
卢克
I'm developing using the Facebook PHP SDK.
I wanted to make it so that when the user logs out of Facebook, they will automatically be logged out of my website too.
I am using the following code to detect the session, using the session cookie:
$facebook->getUser();
For some reason, the getUser()
function still returns the user's Facebook ID, even after they have logged out of Facebook on their website.
Am I to detect the session first using another Function?
On the official documentation example here, is the following excerpt from their comments:
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
This lead me to believe that the session cookie for Facebook would become unset upon Facebook logout?
Kind Regards,
Luke
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我有同样的问题!
FB PHP SDK 将这些内容保存到 $_SESSION 中!
当用户单击注销时,您可以像这样删除它们:
虽然这不是最终的解决方案,但目前它有效。
我很感谢对此的评论和解决方案!
I have the same issue!
The FB PHP SDK saves those things into the $_SESSION!
You can delete them like this when your user clicks logout:
Although this is not the final solution, it works for now.
I appreciate comments and solutions on that!
我想提供一种替代方案,让您不必处理会话内容。不过,我必须警告您,这比清理会话要慢,因为它依赖于新请求。我们在下面的代码中所做的就是在 Facebook 上检查令牌是否仍然有效。如下:
就我而言,我使用 JavaScript SDK 执行所有操作,因此无法在注销时清理会话。但在我的登陆页面中,我需要在发回响应之前进行检查。
如果您遇到这样的事情,这绝对是一个很好的解决方案。
I want to give an alternative, in a way you don't have to handle session stuff. Although, I must warn you this is slower than cleaning up the session, because it relies on a new request. What we're doing in the code below is to check on Facebook if the token is still valid. Here it's:
In my case, I was doing everything using the JavaScript SDK, so I couldn't clean session on logout. But in my landing page, I was needing a work around to check it before send the response back.
If you're facing something like this, definitely a good solution.
问题似乎出在
basefacebook.php
的 php-sdkline 567
中。此方法返回 sdk 正在查找的 cookie 的名称。但是,javascript-sdk 使用“fbs_”前缀。将其更改为“fbs_”即可正常工作。
The problem seems to be in php-sdk in
basefacebook.php
atline 567
This method returns the name of the cookie the sdk is looking for. However, javascript-sdk uses 'fbs_' prefix. Change this to 'fbs_' and it works fine.
要销毁会话,您还可以使用:
$facebook->destroySession();
To destroy the session you can also use:
$facebook->destroySession();