Facebook PHP API 登录窗口弹出 [英] Facebook PHP API login window popup

查看:40
本文介绍了Facebook PHP API 登录窗口弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 facebook 的 php api sdk 的最新版本.我试图让登录按钮激活一个弹出窗口,而不是打开整个页面.我尝试使用本教程:http://thinkdiff.net/facebook/create-facebook-popup-authentication-window-using-php-and-javascript/

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?

这是我生成登录网址的php代码:

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'
    ));
?>

推荐答案

当弹出登录框加载并且用户登录/连接时,该框随后加载站点,并将 ?code=XXX 附加到 url.因此,对于该站点,我添加了一个 php if 语句

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.

这篇关于Facebook PHP API 登录窗口弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆