问题
I have a Facebook Page tab app. For a user who is not logged in, I want to:
- Detect if user is not logged in
- If not logged in, automatically direct user to login
My current approach is to use FB Javascript SDK (in preference to server-side authentication flow):
- On page load, run
FB.getLoginStatus
to check user status - If user is not logged in, run
FB.login
to invoke OAuth dialog
Problem:
FB.login
creates a pop-up dialog (prefer if within Page Tab iframe)- This pop-up dialog is blocked if
FB.login
is not invoked from a button (I would really like to avoid having the user click a button; so would really like to invoke it automatically, when I find a user that is not logged in)
回答1:
I would really like to avoid having the user click a button
FB.login without user interaction -> blocked popup
prefer if within Page Tab iframe
The Auth dialog won’t work inside an iframe, it’s designed that way.
If the automatic call of the login dialog is your most important requirement – then use JavaScript to redirect to the Auth dialog URL, and redirect back to your page/app Facebook address afterwards. See section “Client-side authentication without the JS SDK” here: https://developers.facebook.com/docs/authentication/client-side/
来源:https://stackoverflow.com/questions/11972450/automatically-invoking-fb-login-on-facebook-page-tab-app-for-non-logged-in-user