tags:

views:

45

answers:

1

I swear this was working last night which was why I was able to get to bed at 1am ;). I come into work this morning and now it never gets to the callback of FB.api. The FB.api is an async Facebook JS call...but regardless this was working fine last night and I don't think it's a facebook server (end point) issue.

            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;

                    alert(" defaultAlbumID: " + defaultAlbumID);

                 });
            };


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

    alert("uri: " + uri);

    FB.api(uri, function (response) 
    {
        alert("inside FB.api");
        // 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");

        callbackFunctionSuccess(aAlbums);
    });
}

So it gets to the alert for the uri but never hits the first alert inside the FB.api callback..meaning it never hits alert("inside FB.api"); and I have no clue why.

UPDATED

Looks like all my api calls are being aborted. Not sure what would abort it (the FB server?):

alt text

UPDATED #2

Ok looks like that abort is just saying the Http Request is done. If I right-click that abort line in Firebug and select "Open in new tab" it's showing the HttpResponse data...but I think that's because it's sending a manual request when I do this just like you would copy and paste this request url into a browser manually...

On the other hand if I right-click that abort line and choose "Copy Response Headers" I get nothing. Also when I check this out in Chrome, I see the Request Header but don't see any Response Header.

So still don't get then why it's not entering the callback then if I am getting back data from the FB.api call

UPDATED #3

Ok, got this working again. I had the call to the callback method inside my FB.api's callback. So it was bombing out.

function BindFacebookAlbumAndPhotoData()
{
GetAllFacebookAlbums(userID, accessToken, function(aAlbums) 
{

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

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

};

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

//alert("uri: " + uri);

FB.api(uri, function (response) {
    alert("inside FB.api");

    // 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 FacebookAlbum(
                                        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");
    callbackFunctionSuccess(aAlbums);

}

+1  A: 

Hmm try the following

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

    alert("uri: " + uri);

    FB.api(uri,GetAllAlbumsCallback);
}

function GetAllAlbumsCallback(Data)
{
    alert("inside FB.api");
        // check for a valid response
        if (!Data || Data.error) 
        {
            return;
        }

        for (var i = 0, l = Data.data.length; i < l; i++)
        {
            aAlbums[i] = new Album(
                Data.data[i].id,
                Data.data[i].name,
                Data.data[i].count,
                Data.data[i].link
            );

            if (aAlbums === null || aAlbums === undefined)
            {
                alert("array is empty");
                return false;
            }
            var defaultAlbumID = aAlbums[0].id;
            alert(" defaultAlbumID: " + defaultAlbumID);
        }
}

Just try separate the callbacks from being anonymous, sometimes the there can be scope issues :/

separating them should give them a global scope and generally less error prone.

RobertPitt
CoffeeAddict
yea but at the least I should be hitting the callback of FB.api regardless if I've passed in a callback function reference to GetAllAlbums...and I'm not.
CoffeeAddict
ok Firebug is showing that request as aborted. It's got to be something on the Facebook side then
CoffeeAddict
Updated wtih a screen shot.
CoffeeAddict
you can see in your screenshot that it shows a 302 not found, so if theres no data coming from fb then the callback will not be called.
RobertPitt
Yep. I've submitted a ticket with them. There should be data coming back because I tested a direct url in the browser..the one that is sent and it comes back with data. I'm just not getting a response back from facebook.
CoffeeAddict
I should still get a response with data.length == 0 if there is no data...but in my case I know there's data that should be coming back as this is the same code I was running yesterday.
CoffeeAddict