views:

903

answers:

5

I've a problem with FB.api

I'm making a call to create an event something along the lines of:

 FB.api('/me/events', 'post', {
    access_token: $('#access_token').attr('value'),
    name: td.find('#event_name').attr('value'),
    description: td.find('#description').attr('value'),
    start_time: td.find('#event_start').attr('value'),
    end_time: td.find('#event_end').attr('value'),
    street: td.find('#venue_street').attr('value'),
    city: td.find('#venue_city').attr('value'),
    country: td.find('#venue_country').attr('value')
    }, function(response){
        console.log(response);
});

It works fine until e.g. 'city' is a non-existant city; then the callback function never gets called.

If I examine the AJAX request made using the net panel of firebug, I see the following was the response:

FB.ApiServer._callbacks.f37cab142051f02({
    "error": {
      "type": "Exception",
      "message": "(#151) Unknown city"
    }
}); 

The docs seem to show that I'm doing it right: http://developers.facebook.com/docs/reference/javascript/FB.api

Anyone why the callback function doesn't get called, and how I can catch the error?

+2  A: 

To answer why the callback doesn't get called: The appropriate callback is being executed for me in Chrome, but not Firefox, so I think it has to do with the way the callbacks are handled for an HTTP 500 response in some browsers.

You'll also see the callback is being registered properly, if you manually run that response in your JavaScript console it should handle the error appropriately.

Still not sure how to get it working though, I suspect there will need to be updates the the JavaScript SDK.

Michael Scheibe
A: 

Same problem, those api suck! and there's no support at all for us developers!

What does "if you manually run that response in your JavaScript console it should handle the error appropriately" mean?

Davide
I think the response is javascript code that can be eval'd.To manually run it, find the XHR request in the firebug 'net' tab and copy and paste it into the firebug console to execute it.
EoghanM
A: 

I'm probably missing something obvious, but how do you find/see the XHR request in javascript, rather than just in Firebug? I can see the info in Firebug, but I can't figure out how to get this information in the javascript..

Paul
Hi Paul - in javascript you can add a custom callback function when you are creating the XHR request, or store a reference to the request which you can subsequently check the status of the request. This is the deferred pattern: http://mochikit.com/doc/html/MochiKit/Async.htmlFirebug has access to Firefox internals so can present the info in a sequential way.
EoghanM
A: 

I have the same problem! But it failed on all browsers. In my case I feed on friend's wall - who has blocked feeding option. In firebug net panel i get 500 - Internal server error and this response:

FB.ApiServer._callbacks.f628a2b36c05ac({ "error": { "type": "Exception", "message": "(#210) User not visible" } });

JS graph api should be open source!

przemeko
A: 

Me too. Same issue, no callback fired on 210 error. Guess I'll try to do it server side.

related questions