Skip to content

Instantly share code, notes, and snippets.

@baptx
Last active December 4, 2020 23:29
Show Gist options
  • Save baptx/1979bafebbbc202735f845f5a39f7929 to your computer and use it in GitHub Desktop.
Save baptx/1979bafebbbc202735f845f5a39f7929 to your computer and use it in GitHub Desktop.
Facebook Graph API groups members intersection (deprecated)
/*
* config
*/
var token = "XXX";
var limit = 5000;
var id1 = "XXX";
var id2 = "XXX";
/*
* end config
*/
function getApiUrl(id, token, limit)
{
return `https://graph.facebook.com/v2.9/${id}/members?access_token=${token}&limit=${limit}`;
}
function getData(url)
{
var array = [];
do {
xhr.open("GET", url, false);
xhr.send();
var object = JSON.parse(xhr.responseText);
array = array.concat(object.data);
url = object.paging.next;
} while (url);
return array;
}
var xhr = new XMLHttpRequest();
var url1 = getApiUrl(id1, token, limit);
var array1 = getData(url1);
var url2 = getApiUrl(id2, token, limit);
var array2 = getData(url2);
var length1 = array1.length;
var length2 = array2.length;
var intersect = [];
for (var i = 0; i < length1; ++i) {
for (var j = 0; j < length2; ++j) {
if (array1[i].id == array2[j].id) {
intersect.push(array1[i]);
}
}
}
console.log(intersect);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment