Take the 2-minute tour ×

We are using Facebook JavaScript SDK to authenticate our Facebook application. The application is configured with the Canvas URL as http://facebook.elgifto.com/Home/Index/. Following is the code we are using to authenticate the Facebook user.

    <script type="text/javascript">
          window.fbAsyncInit = function() {
                      appId: '<%= ViewData["AppId"].ToString() %>', // App ID
                      channelUrl: '<%= ViewData["ChannelUrl"].ToString() %>', // Channel File
                      status: true, // check login status          
                      xfbml: true,  // parse XFBML
                      oauth: true

              FB.Event.subscribe('auth.login', function(response) {
                  if (response.status === 'connected') {
                      // the user is logged in and connected to your
                      // app, and response.authResponse supplies
                      // the user’s ID, a valid access token, a signed
                      // request, and the time the access token 
                      // and signed request each expire
                      var uid = response.authResponse.userID;
                      var accessToken = response.authResponse.accessToken;
                      startApp(uid, accessToken);



          // Load the SDK Asynchronously
          (function(d) {    
              js.src = "//connect.facebook.net/en_US/all.js";
          } (document));

          function startApp(uid, accessToken) {                 
              var baseUrl = '<%= ViewData["AppBaseURL"].ToString() %>';
              var redirectUrl = baseUrl + '?uid=' + uid + '&accessToken=' + accessToken;
              window.top.location.href = redirectUrl;
              //document.location = redirectUrl;
<fb:login-button onlogin="initiateLogin()" perms="email,user_about_me,user_birthday,friends_about_me,friends_birthday">Login with Facebook</fb:login-button>

The above code is not working in the Facebook when accessed as http://apps.facebook.com/giftguru. However we are able to access it through http://facebook.elgifto.com/Home/Index

share|improve this question
What do you mean by not working?! any errors? or it's not loading the frame at all? have you set the secure link (SSL)?! –  ifaour Mar 22 '12 at 11:25
I get the error "The connection has timed out". –  mohang Mar 26 '12 at 11:57

4 Answers 4

up vote 4 down vote accepted

The issue is related to pop-up blocking by browser. (the fact that is working for you outside of Facebook is probably because you're allowed to do so sometimes before, for me it's blocked as well as within application).

You should never call FB.login without interaction from user (like element click or form submit) to ensure browser isn't blocking log-in window.

You mixing many things here:

  1. Page on http://facebook.elgifto.com/Home/Index is using Application #316853928368079 (this app and have no namespace!)
  2. Your URL for OAuth Dialog have ' (apostrophe) around client_id which is wrong!
  3. OAuth Dialog isn't working (probably also due to app settings, App Domain?)
  4. Application located on http://apps.facebook.com/giftguru is Application #83808922524 and have wrong Canvas URL! Proof:
    Facebook App Canvas wrapper
share|improve this answer
I tried this solution and it did not work. I changed the code now, please see the changed code. It works when accessed with facebook.elgifto.com/Home/Index. But when I access it with apps.facebook.com/giftguru, I get "The connection has timed out". –  mohang Mar 26 '12 at 11:56
@mohang, your canvas isn't set to http://facebook.elgifto.com/Home/Index/ but so I'm not able to see it and check –  Juicy Scripter Mar 26 '12 at 12:01
@mohang, that configuration issue alone may be reason for that "connection has timed out" error... –  Juicy Scripter Mar 27 '12 at 9:03
Can you please explain which configuration issue you are talking about? –  mohang Mar 28 '12 at 7:11
@mohang, I talking about the fact that your Canvas URL in Application Settings isn't pointing to the same page you talking about (http://facebook.elgifto.com/Home/Index) but to totally different URL ( Ensure that Canvas URL is configured properly. BTW, /html/home.html isn't event exists in your app on facebook.elgifto.com) –  Juicy Scripter Mar 28 '12 at 9:10

I hope this is helpful to you

        window.fbAsyncInit = function() {
            appId      : 'xxxxxxx',
            status     : true, 
            cookie     : true,
            xfbml      : true,
            oauth      : true,
           js.src = "//connect.facebook.net/en_US/all.js";

       function login() {
        FB.login(function(response) {
            if (response.authResponse) {
                alert('Login Failed!');
        }, {scope: 'email'});
      <div onclick="login();">Login with Facebook</div>
share|improve this answer

Also check if your app on deveopers.facebook.com isn't in sandbox mode. I had an issue login worked fine with my main account (which was app admin), but not with other facebook accounts. Later I realized fb app was still in sandbox mode and I had to add each account who was testing as Tester or Developer or disable sandbox mode.

Maybe this will help somebody, I spent an hour before figuring it out. :)

share|improve this answer

Facebook suddenly switched from using their Facebook dialog method to display the authentication window to old-fashioned popup-windows today. Until now, popup windows have only been used when running apps outside a Facebook tab/canvas. This means that you can no longer run FB.login on load and use a click event instead to avoid popup blockers.

The only documentation from Facebook we've found on this is at https://developers.facebook.com/docs/concepts/login/permissions-login-dialog/, but apparently, this popup-window method has been available for games for several weeks now.

share|improve this answer

Your Answer


