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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:04:15+00:00 2026-05-30T23:04:15+00:00

I am trying to determine through some flag when this asynchronous function ends. This

  • 0

I am trying to determine through some flag when this asynchronous function ends.

This is how I call my function:

// Calling the function in a loop
for (var i=0,l=myIds.length; i<l; ++i) {
    install(pageId, myIds[i], apps_num[''+myIds[i]], <?php echo $this->comid ?>, '<?php echo $this->site_url; ?>');
}

And this is my function:

install: function(pageId, appId, app_num, com_id, siteurl) {
    FB.getLoginStatus(function(response) {
        // Checking if connected to Facebook
        if (response.status === 'connected') {
            var uid = response.authResponse.userID;
            console.log(response.authResponse);
            var userAccessToken = response.authResponse.accessToken;

            // Get page access token
            FB.api('/'+pageId+'?fields=access_token='+userAccessToken, function(response) {
                var pageAccessToken = response.access_token;

                // Get information if user got this application
                FB.api('/'+pageId+'/tabs/'+appId+'?access_token='+pageAccessToken,
                    function(data) {
                        if (data.data.length < 1) {
                            console.log("Not installed, Installing...");

                            // Install the application
                            var params = {};
                            params['app_id'] = appId;
                            FB.api('/'+pageId+'/tabs?access_token='+pageAccessToken, 'post', params, function(response) {
                                if (!response || response.error) {
                                    console.log("Error Installing!");
                                }
                                else {
                                    console.log("Installed :)");
                                }
                            });
                        }
                        else {
                            console.log("Already installed.");
                        }
                    });
                });
            }
            else
                if (response.status === 'not_authorized') {
                    console.log("the user is logged in to Facebook, but not connected to the app.");
                }
                else {
                    console.log("the user isn't even logged in to Facebook.");
                }
            });
        }

How can I solve this issue? I tried to use static variables, but I wasn’t able to call them inside the asynchronous function..

  • 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-05-30T23:04:17+00:00Added an answer on May 30, 2026 at 11:04 pm

    The usual thing is to have any code that needs to know the outcome of an asynchronous call pass a function reference into the call, which the function then calls when it’s done (a “callback”).

    So in your case, you’d add a callback parameter to your install function:

    install: function(pageId, appId, app_num, com_id, siteurl, callback)
    //                                        here ------------^
    

    …and then call it when appropriate from the callbacks you’re passing into FB.getLoginStatus and/or FB.api, e.g. something like this:

    install: function(pageId, appId, app_num, com_id, siteurl, callback) {
            FB.getLoginStatus(function(response) {
                           // checking if connected to facebook
                  if (response.status === 'connected') {
                    var uid = response.authResponse.userID;
                    console.log(response.authResponse);
                    var userAccessToken = response.authResponse.accessToken;
    
                    // get page access token
                    FB.api('/'+pageId+'?fields=access_token='+userAccessToken, function(response) {
                        var pageAccessToken = response.access_token;
    
                        // get information if user got this app
                        FB.api('/'+pageId+'/tabs/'+appId+'?access_token='+pageAccessToken,
                           function(data) {
                             if (data.data.length < 1) {
                                 console.log("Not installed, Installing...");
    
                                // install the app
                                 var params = {};
                                 params['app_id'] = appId;
                                 FB.api('/'+pageId+'/tabs?access_token='+pageAccessToken, 'post', params, function(response) {
                                     if (!response || response.error) {
                                        callback(false, "Error installing");
                                        console.log("Error Installing!");
                                     } else {
                                        callback(true, "Installed");
                                        console.log("Installed :)");
    
                                     }
                                    });
                             }
                             else {
                                 callback(false, "Already installed.");
                                 console.log("Already installed.");
                             }
                         });
                    });
                  } else if (response.status === 'not_authorized') {
                    callback(false, "Logged in but not connected.");
                    console.log("the user is logged in to Facebook, but not connected to the app.");
                  } else {
                    callback(false, "Not logged in.");
                    console.log("the user isn't even logged in to Facebook.");
                  }
                 });
          }
    

    There I’ve given the callback function two arguments: A boolean saying whether the installation was performed, and a status message.

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

Sidebar

Related Questions

I'm trying to determine, based on the result of this call, if it was
I am trying to determine if my application is closed through clicking the X
I am trying to perform some computations on a server. For this, the client
I'm trying to go through our development DB right now and clean up some
I'm trying to determine why my validation function is not being called on my
Hey all, I am trying to determine the status of some servers over the
I am currently trying to send binary data out through pexpect. For some reason,
Trying to determine if it is possible to bind the SelectedValue of a ComboBox
Am trying to determine the best way to persist information from an originating email,
I trying to determine display vertical size of my Blackberry Storm 2. I know,

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.