Last active
December 4, 2020 23:29
-
-
Save baptx/1979bafebbbc202735f845f5a39f7929 to your computer and use it in GitHub Desktop.
Facebook Graph API groups members intersection (deprecated)
This file contains 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
/* | |
* 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