facebookjs-sdk取消授权应用程序仍然在FB.getLoginStatus中连接

facebook js sdk deauthorizing app still results as connected in FB.getLoginStatus

本文关键字:FB getLoginStatus 连接 取消 授权 应用程序 facebookjs-sdk      更新时间:2023-09-26

我使用Facebook JS SDK让用户将他们的Facebook帐户连接到我的网站,但我遇到了一个奇怪的问题。

当你按照以下步骤操作时:

- connect for the first time with your fb account, 
- authorize my app, 
- go in another tab in your browser to the facebook website, 
- remove my app, 
- go back to my website tab in your browser 
- click the connect button again

FB.getLoginStatus仍然将response.status返回为"已连接",直到您刷新我的网站选项卡,然后它才会将response.status显示为"未授权"。

即使是FB.login也会将response.status返回为"已连接",直到我刷新窗口(尽管在此之前我正在调用FB.logout)

为什么我需要在窗口显示为"未授权"之前刷新它?我该如何解决这个问题?

edit:我正在使用OAuth功能

这是因为"FB.getLoginStatus"响应对象由SDK缓存。

如果您想解决这个问题,只需调用FB.getLoginStatus并将第二个参数设置为true即可。

FB.getLoginStatus(function(response) {
  // this will be called when the roundtrip to Facebook has completed
}, true);

https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/