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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:32:29+00:00 2026-05-25T13:32:29+00:00

I have a problem with the Facebook API. I may not be going the

  • 0

I have a problem with the Facebook API. I may not be going the about this the best way, but here is what I’ve got.

I have a array of request_ids, which I need to convert to user Ids.
I have a while loop which queries the request ids and gets the user id.

function (response) {
    var requestsToSend = new Array();
    var i = 0;

    while (i < response.request_ids.length)
    {
        FB.api('/'+response.request_ids[i], function(res){
            requestsToSend[i] = res['to']['id'];
        });
        i++;
    }
    console.log(requestsToSend[0], requestsToSend[1], requestsToSend[2], requestsToSend[3]);
}

This works fine. However, when I echo the returned ids (console.log) they are undefined, because the FB.api hasn’t yet returned the values/responses.

Is there any way to fire the console.log only once the FB.api has returned values?
I don’t really want to set a timer to fire the 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-25T13:32:30+00:00Added an answer on May 25, 2026 at 1:32 pm

    Iv fixed the issue but not very happy with the solution

        function (response) {
    
                var requestsToSend = new Array();
                var i = 0;
                var arry = new Array();
    
    
                            FB.api('/'+response.request_ids[0], function(res){
                                if(typeof res['to'] != 'undefined'){
                                    useResults(res['to']['id']);
                                }
                            });
    
                            FB.api('/'+response.request_ids[1], function(res){
                                if(typeof res['to'] != 'undefined'){
                                    useResults(res['to']['id']);
                                }
                            });
    
                            FB.api('/'+response.request_ids[2], function(res){
                                if(typeof res['to'] != 'undefined'){
                                    useResults(res['to']['id']);
                                }
                            });
    
                            FB.api('/'+response.request_ids[3], function(res){
                                if(typeof res['to'] != 'undefined'){                
                                    useResults(res['to']['id']);
                                }
                            });
    
                    function useResults(value){
                        arry.push(value);
                        timeToFire(arry);
                    }
    
                    function timeToFire(arry){
    
                        if(arry.length == response.request_ids.length){
                            //console.log(arry);
                            playTheGame(arry[0], arry[1], arry[2], arry[3]);
                        }
                    }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is hard to explain but if you go here: https://developers.facebook.com/docs/reference/api/ You will see
I have a problem with API call on Facebook Graph API. This API call
I have been using facebook api for a time, but recently there is a
I have a question about the Android Facebook API singleSignOn() method. The code below
I have checked some documentions about the Facebook api that communicates with flash and
Working with the Facebook API makes my ears bleed, but nonetheless I've got a
Odd question, but you have to know first that Facebook API defines all the
We have a problem creating photo album in facebook using android and graph API.
I have a problem. I want to use the facebook api and make a
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE

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.