title: FB.login spawns new window and cannot get access token
body: <p>Been looking around google and StackOverflow, everybody practically have the same advice to do:</p>
  
  <pre><code>FB.login(function(response) {
      if (response.authResponse) {
          var accessToken = response.authResponse.accessToken;
      }
  });
  </code></pre>
  
  <p>I have a "share" button on the page, and when click I simply want to do a post on the user's profile and going to use the <a href="https://graph.facebook.com/me/feed" rel="nofollow">https://graph.facebook.com/me/feed</a> call to do it. To be able to do that, I need the access_token from facebook, so what I did was:</p>
  
  <p>(after calling FB.init() as well as adding the all.js)</p>
  
  <pre><code> FB.login(function (response) {
      console.log('response.authResponse: ' + response.authResponse);
       if (response.authResponse) {
                  var access_token = FB.getAuthResponse()['accessToken'];
                  console.log('Access Token = ' + access_token);
                  FB.api('/me', function (response) {
                      console.log('Good to see you, ' + response.name + '.');
                  });
       } else {
                  console.log('User cancelled login or did not fully authorize.');
       }
    }, { scope: 'user_about_me' });
  </code></pre>
  
  <p>What I expect to happen is that it will open a login dialog for the user to facebook, once they login, the dialog closes, it goes back to my page and I get the access token.</p>
  
  <p>But what happens is that it spawns a new browser window to facebook with the login dialog, once the user login, the page proceeds to the user's news feed page and my callback above never gets called. So basically the control is gone and transferred to the new browser window as a normal facebook browsing for the user. When I close that new window though, it execute the "User cancelled login" on my logging.</p>
  
  <p>What am I missing here? All resources simply suggest to call FB.login and that's what I already doing, but I cant seem to get access token for the user.</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT: Full Code and more comments</strong></p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
      window.fbAsyncInit = function ()
      {
          FB.init(
          {
              appId: '&lt;%= this.ApplicationId %&gt;', // App ID
              channelURL: '&lt;%= this.ChannelFileUrl %&gt;', // Channel File
              status: true, // check login status
              cookie: true, // enable cookies to allow the server to access the session
              oauth: true, // enable OAuth 2.0
              xfbml: true  // parse XFBML
          });
  
          // Additional initialization code here
      };
  
      // Load the SDK Asynchronously
      (function (d)
      {
          var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; }
          js = d.createElement('script'); js.id = id; js.async = true;
          js.src = "//connect.facebook.net/&lt;%= this.LocaleCode %&gt;/all.js";
          d.getElementsByTagName('head')[0].appendChild(js);
      } (document));
  &lt;/script&gt;
  </code></pre>
  
  <p>and then in some js file calling this function (the parameters are not being used yet because haven't really make a post)</p>
  
  <pre><code>function postToFacebook(name, caption, description, link, picture, id) {
  
  var accessToken = "";
  
  console.log('fb event subscribe');
  FB.Event.subscribe('auth.login', function () {
      console.log('facebook event auth.login');
  });
  
  console.log('fb login');
  
  FB.login(function (response) {
          console.log('response.authResponse: ' + response.authResponse);
          if (response.authResponse) {
              var access_token = FB.getAuthResponse()['accessToken'];
              console.log('Access Token = ' + access_token);
          } else {
              console.log('User cancelled login or did not fully authorize.');
          }
  }, {});
  </code></pre>
  
  <p>}</p>
  
  <p>and sequence of what happen is:</p>
  
  <ol>
  <li>printed 'fb event subscribe'</li>
  <li>printed 'fb login'</li>
  <li>Code hits FB.login -> opens a new browser window to facebook, after user login the focus stays in that new window, it never goes in to the callback function in the FB.login</li>
  <li>If I close the window spawned in step 3 above, then the callback function is called and 'User cancelled login or did not fully authorize.' is printed ('response.authResponse: ' gives null)</li>
  </ol>
  
  <p>Step 1 and 2 are expected, Step 3 is the problem, also the window that open has the url <a href="https://www.facebook.com/home.php?_rdr" rel="nofollow">https://www.facebook.com/home.php?_rdr</a></p>