Skip to content

Instantly share code, notes, and snippets.

@lushchick
Created August 25, 2011 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lushchick/1170368 to your computer and use it in GitHub Desktop.
Save lushchick/1170368 to your computer and use it in GitHub Desktop.
Get facebook user ids from sent requests callback using batch requests
FB.ui(
{
method: 'apprequests',
title: SP.copy._('js_invite_title'),
message: SP.copy._('js_invite_message')
},
function(response){
if (!FB.Dialog._stack.length) $('#sp_overlay').hide();
if (!response) return;
var batchStack = [],
batchStackPool = [],
maximumBatchLength = 20; // currently number of batch requests is limited to 20
for (var i = -1, length = response.request_ids.length; ++i < length;) {
batchStack.push({
'method': 'GET',
'relative_url': response.request_ids[i]
});
if (batchStack.length === maximumBatchLength) {
batchStackPool.push(batchStack);
batchStack = [];
};
};
if (batchStack.length) {
batchStackPool.push(batchStack);
};
// loop through pool by maximumBatchLength
while (batchStackPool.length > 0) {
FB.api('/', 'POST', { batch: batchStackPool.shift() }, function(resp) {
var sentUids = [];
for (var i = -1, length = resp.length; ++i < length;) {
sentUids.push(jQuery.parseJSON(resp[i].body).to.id);
};
SP.Ajax.request({
method: '/index/save.requests',
params: { uids: sentUids }
});
sentUids = [];
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment