简体   繁体   English

Facebook SDK注销功能问题

[英]Facebook SDK Logout Function Issue

I'm using the Facebook PHP SDK in combination with the JS SDK on my site. 我在网站上结合使用了Facebook PHP SDK和JS SDK。 Basically, the JS API logs the user in, and then the PHP part fetches all the user's info to display on the page. 基本上,JS API登录用户,然后PHP部分获取所有用户信息以显示在页面上。

The logging in part works fine: The user clicks on a button, that brings up the dialog FB dialog box. logging部分工作正常:用户单击一个按钮,将弹出对话框FB对话框。 The logout function works on an onClick event too, except it doesn't really work, kind of. logout功能也可以在onClick事件上使用,但实际上并不能真正起作用。 It does log the user out successfully, but when it redirects back to the homepage, an exception is thrown: 它确实成功注销了用户,但是当它重定向回首页时,将引发异常:

"Error validating access token: The session is invalid because the user logged out". “验证访问令牌出错:该会话无效,因为用户已注销”。

When the page is refreshed, the error disappears. 刷新页面后,错误消失。 Could this be due to the logout function not properly deleting the session? 这可能是由于注销功能未正确删除会话导致的吗?

Here's the function I use to logout the user: 这是我用来注销用户的功能:

function FBLogout(){
   event.preventDefault();
   FB.logout(function(response){
      window.location.href = 'http://www.mydomain.com/';
   });
}

Any suggestions on how to solve this? 关于如何解决这个问题有什么建议吗?

Facebook must be throwing this error as a response to an API call. Facebook必须将此错误作为对API调用的响应。

After you logout the user successfully, then a call has been sent to the facebook that is failed and this error was returned. 成功注销用户后,呼叫已发送到Facebook,但失败,并返回此错误。

Edit: 编辑:

Logging out from the JS-SDK wont invalidate the access token generated by the PHP SDK. 从JS-SDK注销将不会使PHP SDK生成的访问令牌无效。

So do this- 这样做-

  • In the callback of FB.logout , call $facebook->destroySession() - you can do this by making an ajax call to a page with this call, and then on callback the user will be logout form both JS, and PHP FB.logout的回调中,调用$facebook->destroySession() -您可以通过使用此调用对页面进行ajax调用来执行此操作,然后在回调中,用户将同时从JS和PHP中注销。

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

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