Facebook PHP API 登录窗口弹出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13033790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facebook PHP API login window popup
提问by Todd Low
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/
我正在使用 facebook 的 php api sdk 的最新版本。我试图让登录按钮激活一个弹出窗口,而不是打开整个页面。我尝试使用本教程: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:
这是我生成登录 url 的 php 代码:
<?php
$loginUrl = $me_on_facebook->getLoginUrl(array(
'display' => 'popup',
'next' => $config['baseurl'],
'redirect_uri' => $config['baseurl'],
'scope' => 'email'
));
?>
回答by Todd Low
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
当弹出登录框加载并且用户登录/连接时,该框然后加载站点,并将 ?code=XXX 附加到 URL。因此,对于该站点,我添加了一个 php if 语句
<?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.
这样做是关闭弹出窗口并重新加载启动弹出窗口的原始页面。
回答by Elena Sharovar
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/
您应该使用 Facebook Javascript SDK 并使用 Javascript 函数 FB.login() 授权用户。教程在这里http://developers.facebook.com/docs/reference/javascript/FB.login/

