如何让 Facebook 登录按钮重定向到特定 URL [英] How to let Facebook Login button redirect to a particular URL
问题描述
这是 Facebook 登录按钮上的信息
This is the info on Facebook Login button
http://developers.facebook.com/docs/guides/web/
所以它会呈现一个登录按钮,用户可以点击它登录Facebook(会弹出登录窗口)但是在用户登录后,即使 Like 或 Share 按钮现在可以工作,但登录按钮仍然显示.
So it will render a Login button, and a user can click on it to log in on Facebook (a log in window will pop up) But after the user logs in, even though the Like or Share buttons work now, but the Log in button still shows.
1) 有没有办法在用户成功登录后重定向到 URL?
2)另一种方法是将登录按钮动态更改为不可见或更好,将其显示为以 [Peter (username)] 身份登录"
1) Is there a way to redirect to a URL after the user successfully logs in?
2) Another way is to dynamically change the Log in button to invisible or better yet,
show it as "Logged in as [Peter (username)]"
(1) 和/或 (2) 如何完成?(我在 Facebook 应用设置中没有看到回调 URL,而且重定向可能需要从网站上的页面 A 或页面 B 转到不同的 URL)
How can (1) and/or (2) be done? (I don't see a callback URL in the Facebook app setting and also the redirection may need to go to different URL from page A or page B on the website)
更新:我发现了一些关于 <fb:login-button on-login="top.location = '...'; ">
的信息,但是我看到一些网站在进行重定向,但没有 on-login='...'
Update: I found some info about <fb:login-button on-login="top.location = '...'; ">
but I see some website doing the redirect but there is no on-login='...'
推荐答案
1) 您还可以使用如下代码重定向登录(注意 auth.login
事件):
1) You can also redirect on login using some code like this (note the auth.login
event):
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
FB.init({
appId: '??????????????', cookie: true,
status: true, xfbml: true
});
FB.Event.subscribe('auth.login', function () {
window.location = "http://example.com";
});
</script>
<fb:login-button>
Login with Facebook
</fb:login-button>
2) 要确定是否显示或隐藏登录按钮,您可以使用FB.getLoginStatus
来发现用户是否已登录.以下页面可能有用:http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/一个>
2) To determine whether to show or hide the login button, you can use FB.getLoginStatus
to discover whether the user is logged in. The following page might be of use: http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
这篇关于如何让 Facebook 登录按钮重定向到特定 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!