How to check if user is logged in with new facebook php api

前端 未结 1 971
半阙折子戏
半阙折子戏 2021-02-01 07:07

I am migrating my old FB app to the new graph API using the PHP API

I have two pages: public ones (which require no user login) and private ones (which do)

So th

相关标签:
1条回答
  • 2021-02-01 07:42

    If I am reading your code correctly, only if no session is returned do you do the redirect? According to comments in Facebook's example, even if you get a session back, you can't assume it's still valid. Only trying an API call that requires a logged in user will you know for sure. This is the best way I've seen to reliably determine login/logout status.

    if ($session) {
      try {
        $me = $facebook->api('/me');
        if ($me) {
          //User is logged in
        }
      } catch (FacebookApiException $e) {
        //User is not logged in
      }
    }
    
    0 讨论(0)
提交回复
热议问题