Android Batch Request Sometimes Returns: FacebookException: Unexpected number of results

194 Views Asked by At

We are using the FB Android SDK RequestBatch::executeAndWait() to send a batch request to the retrive some information about photos. The number of requests in this batch is less than 50. However, sometimes we see an exception being thrown: FacebookException: Unexpected number of results.

Further investigation shows that the exception being thrown is in Request::createResponseFromObject method.

if (!(object instanceof JSONArray) || ((JSONArray) object).length() != numRequests) {
        FacebookException exception = new FacebookException("Unexpected number of results");
        throw exception;
}

This exception is not thrown always but randomly on certain android devices and not always on same queries. Any clues on why this might be happening will be very useful. Following is a sample batch request.

  • Request:
  • Id: 42
  • URL: https://graph.facebook.com
  • Method: POST
  • User-Agent: FBAndroidSDK.3.6.0
  • Content-Type: multipart/form-data; boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f
  • batch_app_id: APP_ID
  • batch[{ "relative_url": "SOME_PHOTO_ID1?access_token=ACCESS_TOKEN&fields=images,place.fields(id)&format=json&sdk=android", "method": "GET" }, { "relative_url": "SOME_PHOTO_ID2?access_token=ACCESS_TOKEN&fields=images,place.fields(id)&format=json&sdk=android", "method": "GET" }, { "relative_url": "SOME_PHOTO_ID3?access_token=ACCESS_TOKEN&fields=images,place.fields(id)&format=json&sdk=android", "method": "GET" }, { "relative_url": "SOME_PHOTO_ID4?access_token=ACCESS_TOKEN&fields=images,place.fields(id)&format=json&sdk=android", "method": "GET" }, .... more such requests < 50 ]

The response is something like this: Sorry, something went wrong. We're working on it and we'll get it fixed as soon as we can. See example below. !http://www.weliveinbritain.co.uk/wp-content/uploads/2012/11/ss-facebook1.png

The problem is this exception is thrown randomly and not always on the same query. So not really repeatable consistently. Any help on the possible reasons will be deeply appreciated.

0

There are 0 best solutions below