SHARE
TWEET

facebook_graph_api.js (groups members intersection)

baptx Sep 11th, 2017 (edited) 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  *  config
  3.  */
  4.  
  5. var token = "XXX";
  6. var limit = 5000;
  7.  
  8. var id1 = "XXX";
  9. var id2 = "XXX";
  10.  
  11. /*
  12.  * end config
  13.  */
  14.  
  15. function getApiUrl(id, token, limit)
  16. {
  17.     return `https://graph.facebook.com/v2.9/${id}/members?access_token=${token}&limit=${limit}`;
  18. }
  19.  
  20. function getData(url)
  21. {
  22.     var array = [];
  23.    
  24.     do {
  25.         xhr.open("GET", url, false);
  26.         xhr.send();
  27.         var object = JSON.parse(xhr.responseText);
  28.         array = array.concat(object.data);
  29.         url = object.paging.next;
  30.     } while (url);
  31.    
  32.     return array;
  33. }
  34.  
  35. var xhr = new XMLHttpRequest();
  36.  
  37. var url1 = getApiUrl(id1, token, limit);
  38. var array1 = getData(url1);
  39.  
  40. var url2 = getApiUrl(id2, token, limit);
  41. var array2 = getData(url2);
  42.  
  43. var length1 = array1.length;
  44. var length2 = array2.length;
  45.  
  46. var intersect = [];
  47.  
  48. for (var i = 0; i < length1; ++i) {
  49.     for (var j = 0; j < length2; ++j) {
  50.         if (array1[i].id == array2[j].id) {
  51.             intersect.push(array1[i]);
  52.         }
  53.     }
  54. }
  55.  
  56. console.log(intersect);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top