简体   繁体   English

Facebook PHP。 登录并重定向后,用户需要手动刷新页面

[英]Facebook PHP. after login and redirect, user needs to manually refresh page

I'm having a problem with a user logging in: 我在登录时遇到问题:

1) click facebook login button 1)点击facebook登录按钮

2) user fills in information on facebook site 2)用户在Facebook网站上填写信息

3) user is redirected to my site 3)用户被重定向到我的网站

4) this code is then run: 4)然后运行此代码:

if ($user) 
{       
    try 
    {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
        $fb_user_id = $user_profile['id'];
        ...

The api call fires an error: api调用会引发错误:

OAuthException: An active access token must be used to query information about the current user. OAuthException:必须使用活动访问令牌来查询有关当前用户的信息。

5)the user is treated as if they never logged in. 5)将用户视为从未登录过。

6)manually refreshing the page causes the session to be recognized and the api call does not throw an error. 6)手动刷新页面可识别会话,并且api调用不会引发错误。

What is going on? 到底是怎么回事? do I need to put a delay in? 我需要延迟一下吗?

I may have the answer for you. 我可能会为您解答。 After fiddling with the same issue (after successful login, no refresh). 遇到相同问题(成功登录后,无刷新)。 I tried adding window.location.reload() upon login event to no avail 我尝试在登录事件后添加window.location.reload()无济于事

this, however, seems to do the trick for me: 但是,这似乎对我有用:

FB.Event.subscribe('auth.login', function(response) {
    window.location.href=window.location.href;
}

I was using the FB JS library incorrectly. 我没有正确使用FB JS库。

EDIT : I don't remember the specifics, but I'll try my best 编辑:我不记得具体细节,但我会尽力而为

I'm using the php SDK to see if a user is logged in through facebook, and if it is, save a session and store cookies. 我正在使用php SDK来查看用户是否通过facebook登录,如果是,则保存会话并存储cookie。 The JavaScript SDK is being used to log in a user through facebook then callback to a login page to update my server and store session variables. JavaScript SDK用于通过Facebook登录用户,然后回调到登录页面以更新服务器并存储会话变量。 From what I can remember something was called out of order giving me a getuser problem. 从我的记忆中可以看出,发生了一些问题,这给我带来了getuser问题。 After re-reading the example files given with the sdk, it began to work. 重新读取sdk提供的示例文件后,它开始工作。

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

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