Created
August 25, 2011 10:08
-
-
Save lushchick/1170368 to your computer and use it in GitHub Desktop.
Get facebook user ids from sent requests callback using batch requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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