I have a strange problem here that I'm hoping someone can offer some hints to.
We have a Facebook Canvas application setup and working. However, the problem is that the install screen that prompts the user to allow access is trying to redirect to the main application screen BEFORE the AJAX call to create the user completes. This results in the user getting redirected back to the install screen where they have to click the authorize button a 2nd time.
So the sequence of events looks like this:
- User visits the application for the first time and is redirected to the install screen to get their permission.
- User clicks the authorize button (<fb:login-button>) and clicks Allow in the dialog window
- User is redirected to the main application page
- Main application page says the user does not have a Drupal account yet and redirects them back to the install screen
- The install screen displays (with the URL argument: ?_fb_user_fbu=10000123456)
- The Drupal user account is finally created
- The user clicks the authorize button again and gets correctly routed to the main page
Our Authorize button uses the following code:
<fb:login-button perms="user_about_me,user_birthday,user_location,publish_stream,offline_access" onlogin="FB_JS.reload('http://apps.facebook.com/myappname/gp');"><fb:intl>Get Started</fb:intl></fb:login-button>
The /gp page of the site is a simple router function that checks fb_facebook_user() to see if the current user has a Facebook ID. If they don't, they get routed to the install screen. Otherwise they get routed to the main page of the app.
Finally the other pages of the app use drupal's user_is_anonymous() function to see if the user is logged in and if not, redirect them to the install screen.
What is the correct process for prompting a user to authorize your application and then redirect them to the main page after their user account is created?
Comments
Comment #1
Dave Cohen commentedDon't use
onlogin="FB_JS.reload('http://apps.facebook.com/myappname/gp');".Instead do something like
onlogin="Drupal.settings.fb.reload_url='http://apps.facebook.com/myappname/gp';"This way, the ajax callback will create the new acocunt and when the page reloads it will already exist.
Let us know if that works. I'm not sure if onclick or onlogin is the right attribute, either might work.
Comment #2
shawn_smiley commentedAwesome! Thanks Dave!
Using onlogin="Drupal.settings.fb.reload_url='http://apps.facebook.com/myappname/gp';" solved the problem.
Comment #3
Dave Cohen commentedcool.