开发者

Method callback not being hit

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 http://elbalazo.net/post/abortedcalls.jpg

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);

}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜