Facebook getUser() function returning user ID after logout

后端 未结 5 1234
梦谈多话
梦谈多话 2020-12-28 18:28

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.<

5条回答
  •  一个人的身影
    2020-12-28 19:01

    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:

    try {
        $facebook->api('/me','GET');
        $logged = true;
    } catch(FacebookApiException $e) {
        $logged = false;
    }
    

    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.

提交回复
热议问题