Reliability Bug in Facebook PHP API Batching Support
I recently discovered a bug in the current Facebook API PHP Client library that affects the support for batching calls which I’ve used for the Selective Twitter Status application.
The bottom line is, sometimes the call to batch.run within execute_server_side_batch() as called by end_batch() returns an empty string instead of the expected array of results from each of the batched calls. The code has the following test for an exception but this isn’t triggered in it’s current state since no specific FB exception is being returned, just the empty result:
if (is_array($result) && isset($result['error_code'])) {
throw new FacebookRestClientException($result['error_msg'],
$result['error_code']);
}
The symptom is a bunch of PHP warnings similar to the following as the code attempts to iterate over the empty string as if it was the expected array of results:
PHP Notice: Uninitialized string offset: 0 in [...]/facebook/facebookapi_php5_restlib.php on line 210 PHP Notice: Uninitialized string offset: 1 in [...]/facebook/facebookapi_php5_restlib.php on line 210
etc
In my experience the empty result has been in situations where the requested batch operations haven’t been performed, so the fix is to add a test for the empty result and to treat this as an exception. This was my hack:
if (!isset($result[0])) {
throw new FacebookRestClientException('Batch call returned invalid result: ' . var_export($result, true) . '; ' . var_export($xml, true), 9999);
}
As a side note, the batching support as implemented in the current PHP API client is rather limited since if one of the batched functions returns an exception it is thrown immediately, with the result that the return values of subsequent calls are not populated and it’s impossible to know whether they executed successfully. I’ve changed the line that threw the exception to instead set the FacebookRestClientException object as the return value for the relevant call as follows:
for($i = 0; $i batch_queue[$i];
$batch_item_result_xml = $result[$i];
$batch_item_result = $this->convert_xml_to_result($batch_item_result_xml, $batch_item['m'], $batch_item['p']);
if (is_array($batch_item_result) &&
isset($batch_item_result['error_code'])) {
// PATCH: modify to return the Exception object as the result for this call so we can process all results/exceptions
$batch_item_result = new FacebookRestClientException($batch_item_result['error_msg'], $batch_item_result['error_code']);
}
$batch_item['r'] = $batch_item_result;
}
Hopefully this helps anyone searching Google..
If you can’t find yourself in Twitter Search..
I just came across a recent help page from Twitter (from June) about what to do if your tweets are not showing up in the twitter search. As it already says on the Selective Twitter Status help page, your tweets not showing in Twitter search is one of the most common reasons for the app not working for you, particularly if it used to work but suddenly stopped.
To check if your tweets are coming up in Twitter search go to http://search.twitter.com/ and type in your twitter username. For example, my tweets should show up at http://search.twitter.com/search?q=andyy. If your tweets don’t appear, Twitter basically say to check Twitter isn’t having any problems at the moment, and if everything is otherwise fine (and your account is public, of course) then your tweets “have most likely been filtered out of our search index for quality reasons” which sadly isn’t much help (unless you really have been spamming, in which case you just gotta live with it.. ;)
As I mention on the help page, the last thing to try is to protect your Twitter account and then make it public again. You’ll need to post a new tweet after doing this to check if it worked.
New website..Tumblr it is
So, I finally got around to setting up a personal website that I’m not ashamed to show people..
I don’t really blog, but I wanted a home to stick links to my Twitter, FB, LinkedIn profiles etc for people that discover me online, collect links to show off when my projects receive press coverage etc as well as post interesting links and other notes from time to time.
Features I wanted:
- Easy setup, hosted solution, no coding required - I’m lazy, didn’t want to spend time on the technical side of a full Wordpress install etc.
- A service with lots of themes so I could find one I liked and do minimal customisations
- The ability to post stuff with tags, so in future I can set up separate index pages for stuff related to GroupSpaces, Selective Twitter Status, entrepreneurship etc
- My own domain name
- Suitable cool post-from-email/iphone/etc support
- All the above for free!
I looked at Posterous first but it doesn’t support all of the above right now. The winner is Tumblr which was quick to set up, does all the above plus the following bonus features:
- Designed for minimal blogging (posting short snippets, links and videos rather than extended blog posts) that suits the way I want to post
- Handy powerful iPhone app for posting
- Supports Markdown - a handy way of entering formatting quickly as you type
I’ve also integrated commenting powered by Disqus, which took only a couple of minutes and has a bunch of powerful features (sign in with Facebook etc). I think the default Disqus interface confuses visitors with too many features and wordy instructions so I’ve hidden some parts of the comments interface and tweaked some other stuff out of the way using custom CSS.
Let’s see how it goes..
new FB iPhone app fixes Selective Twitter Status issue

The new 3.0 version of the Facebook iPhone app now displays all posts by Selective Twitter Status correctly, even if you have the “show follow link” option turned on in the settings :)
European Entrepreneurs Come to Life with their Latest Creations
Features an interview with David about GroupSpaces