开发者

Facebook PHP SDK 3.0 (check if user is logged in)

I'm trying to use the Facebook PHP SDK 3.0 to be able to know if a user is currently logged on into his facebook account to display his information.

This is the flow:

  1. User comes to my site and connects his account with my facebook app.
  2. User is now logged in on my site, my site can access his information.
  3. User logs out of facebook.com.
  4. User refreshes my开发者_开发百科 page.
  5. User is logged out of my site.
  6. User logs in on facebook.com.
  7. User refreshes my page.
  8. USER SHOULD BE LOGGED IN ON MY SITE BUT ISN'T.

When you use the Javascript SDK, you can check if user is logged in and everything works fine with the steps. What needs to be done with the PHP SDK 3.0? I don't want to give access_offline permissions, I just want to be able to access the user when he's logged in on facebook.com.

Thanks a lot, Jeremie


Add this javascript in all pages(core js). login() and logout() are functions for your system login and logout. By this it will check every time fb is logged in or not and call function for login. And will satisfy condition -

USER SHOULD BE LOGGED IN ON MY SITE BUT ISN'T.

<script type="text/javascript">
            window.fbAsyncInit = function() {
                FB.init({appId: '113700398662301', status: true, cookie: true, xfbml: true});

                /* All the events registered */
                FB.Event.subscribe('auth.login', function(response) {
                    // do something with response
                    login();
                });
                FB.Event.subscribe('auth.logout', function(response) {
                    // do something with response
                    logout();
                });

                FB.getLoginStatus(function(response) {
                    if (response.session) {
                        // logged in and connected user, someone you know
                        login();
                    }
                });
            };
</script>


based on the signed request, u should be able to know if the user has authorized your app before. This should give u some status about the user.

to check if he is logged in to fb, for authorized user, u can try to query "/me" and see if you can query it successfully

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜