Sandbox update

Thursday, August 7, 2008 at 5:07 PM



Here's this week's list of changes to the sandbox...

A couple changes to the prefetcher:
  • Fixed a bug that was causing failures on prefetched requests. This bug showed up intermittently when a user began a new session with an app, usually causing a JavaScript error since the data requested was not returned.
  • Only requests made in a gadgets.util.registerOnLoadHandler() will be prefetched, so make sure your data requests occur in the functions you specify as onLoad handlers (and not, for example, in a makeRequest() callback). For example:
    gadgets.util.registerOnLoadHandler(init);

function init() {
// The results of this data request will be prefetched
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER), "req");
req.send(response);
}
Two improvements for requestSendMessage():
  • The parameter sent to the callback function now contains a property called "recipientIds" that contains the array of IDs for users that were selected to receive the message.
  • If the message quota is exceeded, the error code is now "limitExceeded" (which is equivalent to opensocial.ResponseItem.ErrorCode.LIMIT_EXCEEDED from OpenSocial v0.8).
  • For example:
    function sendMessageCallback(responseItem) {
if (!responseItem.hadError()) {
// Here's how to access the array of recipient IDs
var idArray = responseItem.getData()['recipientIds']);
...
} else {
// Here's how to check if the quota was reached
if (responseItem.getErrorCode() == 'limitExceeded') {
...
}
}
}