我在网站上放了一个“登录Facebook”选项,我设法很顺利地实现了它。我依赖于facebook->getUser()
方法,根据文档returns the Facebook User ID of the current user, or 0 if there is no logged-in user
。
但是,登录后,所有后续的getUser()调用都会返回userId,即使我手动转到facebook并注销。
似乎正在缓存userId或其他东西。我可以看到很多人有同样的问题,但仍然无法找到解决方案。我如何克服这个问题(该网站基于CodeIgniter,我指的是this教程)?
答案 0 :(得分:0)
从我的网站复制粘贴。
$user = $this->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.
$profile = null;
if($user)
{
try {
// Proceed knowing you have a logged in user who's authenticated.
$profile = $this->facebook->api('/me?fields=id,name,link,email');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
如果API没有响应,请查看$ user如何变为null?这是关键。如果你没有完成那一步,那就不行了。即使用户最近退出,getUser有时也会返回一个ID。