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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:06:17+00:00 2026-05-16T02:06:17+00:00

This is just freakin weird to me. So if I don’t function BindAlbumAndPhotoData() {

  • 0

This is just freakin weird to me. So if I don’t

    function BindAlbumAndPhotoData()
    {
        // Get an array of all the user's Albums
        var aAlbums = GetAllAlbums(userID, token);

        alert("aAlbums: " + aAlbums);
        if (aAlbums == null || aAlbums == "undefined")
            return;

        // Set the default albumID
        var defaultAlbumID = aAlbums[0].id;

    };

So I get an undefined error on the line var defaultAlbumID = aAlbums[0].id; if I don’t uncomment the alert(“aAlbums: ” + aAlbums);

what the heck? If I comment out alert(“aAlbums: ” + aAlbums); then I get an undefined for the var defaultAlbumID = aAlbums[0].id;

This is so weird. I’ve been working all night to figure out why I kept getting an undefined for the aAlbum[0] and as soon as I add back an alert that I used to have above it, all is fine…makes no sense to me.

Here’s the full code of GetAllAlbums:

function GetAllAlbums(userID, accessToken)
{
    var aAlbums = []; // array
    var uri = "/" + userID + "/albums?access_token=" + accessToken;

    alert("uri: " + uri);

    FB.api(uri, function (response) 
    {
        // check for a valid response
        if (!response || response.error) 
        {
            alert("error occured");
            return;
        }

        for (var i = 0, l = response.data.length; i < l; i++) 
        {
            alert("Album #: " + i + "\r\n" +
                  "response.data[i].id: " + response.data[i].id + "\r\n" +
                  "response.data[i].name: " + response.data[i].name + "\r\n" +
                  "response.data[i].count: " + response.data[i].count + "\r\n" +
                  "response.data[i].link: " + response.data[i].link
                  );

            aAlbums[i] = new Album(
                                                    response.data[i].id,
                                                    response.data[i].name,
                                                    response.data[i].count,
                                                    response.data[i].link
                                                   );

            alert("aAlbums[" + i + "].id : " + aAlbums[i].id);
        }
    });

    return aAlbums;
}

so I’m not returning the array until I hit the callback of the FB.api async call so I don’t see how my defaultAlbumID = aAlbums[0].id; line of code is executing before I have a valid array of data back. When I put in the alert, ovbvioulsly it’s delaying before it hits my line defaultAlbumID = aAlbums[0].id; causing it to I guess luckily have data beacuse the async FB.api call is done but again I don’t see how that’s even possible to have an issue like this when I’m waiting for the call before proceeding on and returning the array to aAlbums in my BindAlbumAndPhotoData() method.

UPDATE #3

            function BindAlbumAndPhotoData()
            {
                GetAllAlbums(userID, accessToken, function (aAlbums) 
                {
                    alert("we're back and should have data");

                    if (aAlbums === null || aAlbums === undefined) {
                        alert("array is empty");
                        return false;
                    }

                    var defaultAlbumID = aAlbums[0].id;

                    // Set the default albumID
                    var defaultAlbumID = aAlbums[0].id;

                    // Bind the album dropdown
                    alert(" defaultAlbumID: " + defaultAlbumID);

                 });
            };


function GetAllAlbums(userID, accessToken, callbackFunctionSuccess)
{
    var aAlbums = []; // array
    var uri = "/" + userID + "/albums?access_token=" + accessToken;

    FB.api(uri, function (response) 
    {
        // check for a valid response
        if (!response || response.error) 
        {
            alert("error occured");
            return;
        }

        for (var i = 0, l = response.data.length; i < l; i++) 
        {
            alert("Album #: " + i + "\r\n" +
                  "response.data[i].id: " + response.data[i].id + "\r\n" +
                  "response.data[i].name: " + response.data[i].name + "\r\n" +
                  "response.data[i].count: " + response.data[i].count + "\r\n" +
                  "response.data[i].link: " + response.data[i].link
                  );

            aAlbums[i] = new Album(
                                                    response.data[i].id,
                                                    response.data[i].name,
                                                    response.data[i].count,
                                                    response.data[i].link
                                                   );

            alert("aAlbums[" + i + "].id : " + aAlbums[i].id);
        }

        // pass the array back to the callback function sent as a param to the GetAllAlbums method here
        callbackFunctionSuccess(aAlbums); 
    });
}

It’s not hitting my alert in the callback. I must still be doing something wrong here.

UPDATE #4 – for some reason it’s not hitting my FB.api callback now.

function GetAllAlbums(userID, accessToken, callbackFunctionSuccess)
{
    var aAlbums = []; // array
    var uri = "/" + userID + "/albums?access_token=" + accessToken;

    alert("uri: " + uri);

    FB.api(uri, function (response) 
    {
        // check for a valid response
        if (!response || response.error) 
        {
            alert("error occured");
            return;
        }

        for (var i = 0, l = response.data.length; i < l; i++) {
            alert("Album #: " + i + "\r\n" +
                  "response.data[i].id: " + response.data[i].id + "\r\n" +
                  "response.data[i].name: " + response.data[i].name + "\r\n" +
                  "response.data[i].count: " + response.data[i].count + "\r\n" +
                  "response.data[i].link: " + response.data[i].link
                  );

            aAlbums[i] = new Album(
                                                    response.data[i].id,
                                                    response.data[i].name,
                                                    response.data[i].count,
                                                    response.data[i].link
                                                   );

            alert("aAlbums[" + i + "].id : " + aAlbums[i].id);
        }

        alert("about to pass back the array to the callback function");
        // pass the array back to the callback function sent as a param to the GetAllAlbums method here
        callbackFunctionSuccess(aAlbums);
    });
}
  • 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-16T02:06:18+00:00Added an answer on May 16, 2026 at 2:06 am
    function BindAlbumAndPhotoData()
    {
        // Get an array of all the user's Albums
        GetAllAlbums(userID, token, function(aAlbums){
    
            // Set the default albumID
            var defaultAlbumID = aAlbums[0].id;
    
        });
    
    };
    

    and then in the GetAllAlbums function call the success function when you have the data back

    //********* AFTER THE BREAK *******//

    In response to the updated question: The FB API is mostly asynchronous, and will keep executing other code while it waits. So using your code, all I have done is passed in the function, and then call the function you’ve passed it at the end

    function GetAllAlbums(userID, accessToken, funcSuccess)
    {
        var aAlbums = []; // array
        var uri = "/" + userID + "/albums?access_token=" + accessToken;
    
    alert("uri: " + uri);
    
    FB.api(uri, function (response) 
    {
        // check for a valid response
        if (!response || response.error) 
        {
            alert("error occured");
            return;
        }
    
        for (var i = 0, l = response.data.length; i < l; i++) 
        {
            alert("Album #: " + i + "\r\n" +
                  "response.data[i].id: " + response.data[i].id + "\r\n" +
                  "response.data[i].name: " + response.data[i].name + "\r\n" +
                  "response.data[i].count: " + response.data[i].count + "\r\n" +
                  "response.data[i].link: " + response.data[i].link
                  );
    
            aAlbums[i] = new Album(
                                                    response.data[i].id,
                                                    response.data[i].name,
                                                    response.data[i].count,
                                                    response.data[i].link
                                                   );
    
            alert("aAlbums[" + i + "].id : " + aAlbums[i].id);
    
    
    
        }
    
        funcSuccess(aAlbums);
    });
    

    }

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

Sidebar

Related Questions

I don't think that this could be done in C#, but posting this just
This just seems absurd to me. Should I use array instead or is there
Just curious... I begin my jquery code with this: jQuery(document).ready(function($) { /*code here*/ })
This just is't making sense to me at all. This is my code: boolean
This just started happening three weeks or so ago. The content of my website
This just saves time. Since I already have a web applciation. I can just
I fear this just may not be possible, but I'm trying to create a
I'm hoping this just needs a new pair of eyes casting over it. I
So for some reason this just doesn't make sense to me. What Im trying
I assume this just returns an int. Is there anything else going on I

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.