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 8060879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:08:42+00:00 2026-06-05T10:08:42+00:00

In my Canvas App (tab page) I use this code to get the AccessToken

  • 0

In my Canvas App (tab page) I use this code to get the AccessToken if the app needs it:

var accessToken = "";
FB.getLoginStatus(function (response) {
  if (response.authResponse || response.status === 'connected') {
    accessToken = response.authResponse.accessToken;
  }else {
    alert( response.status );
  }
} ); 
return accessToken;

I works fine. BUT if user opens the app and leave it for about 30minutes (or less or more, just for a long time) after this functions can’t get the accessToken just return with an empty string. In the console log there aren’t any error. After if the user refresh the page everything is fine…

What should I do to can get the accessToken anytime?

  • 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-05T10:08:43+00:00Added an answer on June 5, 2026 at 10:08 am

    Here’s what’s going on:

    The FB.getLoginStatus method is done asynchronously, and you give it a callback to execute once finished.
    In your code you return the accessToken right after issuing the async request, but you’re not waiting for it to be completed.
    It should look like:

    FB.getLoginStatus(function (response) {
        if (response.authResponse || response.status === 'connected') {
            return response.authResponse.accessToken;
        } else {
            alert( response.status );
        }
    });
    

    So you might ask yourself “so why does it work to begin with?”, the answer is simple: at first the sdk has the authentication data and does not need to actually make the request to the fb servers, as it states in the documentation of the method:

    Roundtrips to Facebook’s servers

    To improve the performace of your application, not every call to check
    the status of the user will result in request to Facebook’s servers.
    Where possible, the response is cached. The first time in the current
    browser session that FB.getLoginStatus is called, or the JD SDK is
    init’d with status: true, the response object will be cached by the
    SDK. Subsequent calls to FB.getLoginStatus will return data from this
    cached response.

    If you try your code with passing `true’, like this:

    var accessToken = "";
    FB.getLoginStatus(function (response) {
        if (response.authResponse || response.status === 'connected') {
            accessToken = response.authResponse.accessToken;
        } else {
            alert( response.status );
        }
    }, true);
    return accessToken;
    

    Then it should not work at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple facebook canvas app (page tab) with PHP, that posts something
I am developing simple facebook canvas app. I was following this page in documentation:
I am doing a Canvas app inside the facebook page. My very simple question
I am building a Facebook canvas app, and the code suppose to be generated
We're developing a Canvas app that will have a tab when implemented on the
I have a link in my Facebook page tab app which should send the
I wonder if someone can answer this; I have a canvas app, which in
I have made an app which will be a FB page tab. Now I
I am using the Facebook C# SDK in a canvas app. When running this
Short version I have a facebook iframe app as a page tab on a

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.