Facebook PHP API login window popup

有些话、适合烂在心里 提交于 2019-12-20 09:45:01

问题


I'm using using the most recent version of facebook's php api sdk. I'm trying to make the login button activate a popup instead of opening the full page. I tried using this tutorial: http://thinkdiff.net/facebook/create-facebook-popup-authentication-window-using-php-and-javascript/

The popup worked but when I logged in, instead of the popup window closing, the website just opened inside the popup.

Does anybody know what I need to do to make the popup window close once I have logged in?

Here is my php code for generating the login url:

<?php
    $loginUrl = $me_on_facebook->getLoginUrl(array(
        'display' => 'popup',
        'next' => $config['baseurl'],
        'redirect_uri' => $config['baseurl'],
        'scope' => 'email'
    ));
?>

回答1:


When the popup login box loads and the user signs in/connects, the box then loads the site with ?code=XXX appended to the url. So for the site I added a php if statement

<?php
    if (isset($_REQUEST['state']) && isset($_REQUEST['code'])) {
        echo "<script>
            window.close();
    window.opener.location.reload();
        </script>";
} else {
        // load page
    }
?>

What this does is close the popup and reload the original page that initiated the popup.




回答2:


You should use Facebook Javascript SDK and authorize user using Javascript function FB.login(). Tutorial is here http://developers.facebook.com/docs/reference/javascript/FB.login/



来源:https://stackoverflow.com/questions/13033790/facebook-php-api-login-window-popup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!