Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7826013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:14:29+00:00 2026-06-02T09:14:29+00:00

Been looking around google and StackOverflow, everybody practically have the same advice to do:

  • 0

Been looking around google and StackOverflow, everybody practically have the same advice to do:

FB.login(function(response) {
    if (response.authResponse) {
        var accessToken = response.authResponse.accessToken;
    }
});

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 https://graph.facebook.com/me/feed call to do it. To be able to do that, I need the access_token from facebook, so what I did was:

(after calling FB.init() as well as adding the all.js)

 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' });

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.

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.

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.

Thanks in advance!

EDIT: Full Code and more comments

<script type="text/javascript" language="javascript">
    window.fbAsyncInit = function ()
    {
        FB.init(
        {
            appId: '<%= this.ApplicationId %>', // App ID
            channelURL: '<%= this.ChannelFileUrl %>', // 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/<%= this.LocaleCode %>/all.js";
        d.getElementsByTagName('head')[0].appendChild(js);
    } (document));
</script>

and then in some js file calling this function (the parameters are not being used yet because haven’t really make a post)

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.');
        }
}, {});

}

and sequence of what happen is:

  1. printed ‘fb event subscribe’
  2. printed ‘fb login’
  3. 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
  4. 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)

Step 1 and 2 are expected, Step 3 is the problem, also the window that open has the url https://www.facebook.com/home.php?_rdr

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:14:30+00:00Added an answer on June 2, 2026 at 9:14 am

    In the documentation for the FB.login method it says clearly:

    Calling FB.login results in the JS SDK attempting to open a popup
    window. As such, this method should only be called after a user click
    event, otherwise the popup window will be blocked by most browsers.

    If you want to stick to a client side flow then the options that are available for that are mentioned in this tutorial: Client-Side Authentication.

    tsOverflow edit:
    based on the chat discussion with Nitzan Tomer, found out the issue with my work above:

    1. the AppId that was used is registered on facebook to a different Site URL, so even when you are testing locally, need to make sure the AppId has the same domain url
    2. the channel.html was missing
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking around ocn Google and Stackoverflow but haven't found what I
Been looking around stackoverflow and google for ways to solve this issue im having
I have been looking around for a solution that implements this, but google always
I have been looking all around Bing and Google trying to find this, does
I have been looking around for solutions, and tried to implement what is often
I've been looking around for quite a while and feel that I have a
I have been looking around on the web and found some articles about the
I've been looking around Google and SO and haven't quite found an answer to
I've been looking around in Google, but haven't found an answer. Do you guys
I've been looking around on this site and on Google and haven't found anything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.