I'm trying to get the number of members of some Facebook groups. I tried to play with the Facebook Graph API but it does not work:
function facebook(url) {
var jsondata = UrlFetchApp.fetch('http://graph.facebook.com/http://www.facebook.com/groups/449592401822610/?ref=br_rs');
var object = Utilities.jsonParse(jsondata.getContentText());
return object.shares;
}
Is it possible to do that? Thanks for your help
[UPDATE] Sometimes I don't have the ID of the group. I wrote this to solve the issue but it does not work...
function facebook(group) {
if (isNaN(group) == true) {
var jsondata1 = UrlFetchApp.fetch('https://graph.facebook.com/search?q='+group+'&type=group&access_token={my token}');
var object1 = Utilities.jsonParse(jsondata1.getContentText());
var id = object1.data.id;
var jsondata2 = UrlFetchApp.fetch('https://graph.facebook.com/v2.5/'+id+'/members?summary=true&access_token={my token}');
var object2 = Utilities.jsonParse(jsondata2.getContentText());
return object2.summary.total_count;
}
else {
var jsondata = UrlFetchApp.fetch('https://graph.facebook.com/v2.5/'+group+'/members?summary=true&access_token={my token}');
var object = Utilities.jsonParse(jsondata.getContentText());
return object.summary.total_count;
}
}
Any idea?
Using Graph API
https://graph.facebook.com/v2.5/449592401822610/members?summary=true&access_token={user-access_token}
you will get response like this if it is closed group
{
"data": [
],
"summary": {
"total_count": 4113
}
}
and if it is public group you will also receive members detail in data section
Good Luck
NOTE: this will only return count <5000 member. If your group is near 5000 or more than 5000 it will return 4897, 4756, or some other "random" number, but will never return more than 5000.