Facebook login: Check authentication at every page?

前端 未结 2 1101
暖寄归人
暖寄归人 2021-01-26 09:57

I\'m following this guide: https://developers.facebook.com/docs/howtos/login/getting-started/

Everything is working fine with regards to the login. What I don\'t underst

相关标签:
2条回答
  • 2021-01-26 10:43

    I guess FB.getLoginStatus is used instead of sessions?

    FB.getLoginStatus is used to help you optimize your visitors experience based on their login status and hence it's not a replacement of "sessions".

    I have to check FB.getLoginStatus everytime the user enters a new page in my website. Does that mean i have to initialize the JavaScript SDK for every page? Thats 50 lines of code for every page just to check the login status...

    Well, initializing the Javascript SDK is something you have to do if you wish to use the SDK. Now I don't see anything wrong with the numbers of lines of code, as Facebook already loads the SDK asynchronously and hence it won't block your page resources.

    And for your first point, you don't have to call FB.getLoginStatus every time on page load and Facebook already states this in the related document:

    While you can call FB.getLoginStatus any time (for example, when the user tries to take a social action), most social apps need to know the user's status as soon as possible after the page loads. In this case, rather than calling FB.getLoginStatus explicitly, it is possible to check the user's status by setting status: true when you call FB.init.

    To receive the response of this call, you must subscribe to the auth.statusChange event. The response object passed by this event is identical to that which would be returned by calling FB.getLoginStatus explicitly.


    Now one thing that you might have missed, is the PHP-SDK:

    The Facebook SDK for PHP can work in conjunction with the Facebook SDK for Javascript to provide seamless session management across both the client and server-sides of an app.

    This would make your life easier as you would have an idea of the user status upon (before) loading the page and hence customize the user experience accordingly and then wait for any status change triggered by the Javascript SDK.

    0 讨论(0)
  • 2021-01-26 10:49

    From the Facebook Developers area it seems they have a section on how to login without calling their Javascript SDK.

    https://developers.facebook.com/docs/howtos/login/client-side-without-js-sdk/

    The user will have an API access token which can be used for further requests.

    I hope that helps.

    0 讨论(0)
提交回复
热议问题