Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let Facebook Login button redirect to a particular URL

Tags:

facebook

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

like image 540
nonopolarity Avatar asked Mar 04 '11 22:03

nonopolarity


People also ask

How do I redirect a URL after login?

The most common ways to implement redirection logic after login are: using HTTP Referer header. saving the original request in the session. appending original URL to the redirected login URL.

How do I add a login button to Facebook?

#3: Set Up Facebook Login for Your Website At this point, you'll see Facebook Login among your website app options. Click the Set Up button to get started. Next, you'll fill in the information about how and where you'll use the app. You can add the Facebook Login feature on any app across multiple devices.

How do I redirect my Facebook page?

Click Use My Domain on the domain you want to connect to your Facebook page. Click Connect to an Existing Site. Select the Facebook option under the Social Sites section. Type in your Facebook URL, which you can find in the General Account Settings on your Facebook page.


1 Answers

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/

like image 107
Andy Avatar answered Sep 27 '22 21:09

Andy