Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

How to let Facebook Login button redirect to a particular URL

This is the info on Facebook Login button

http://developers.facebook.com/docs/guides/web/

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) 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)]"

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)

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='...'

question from:https://stackoverflow.com/questions/5200167/how-to-let-facebook-login-button-redirect-to-a-particular-url

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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) 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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...