Created
December 24, 2018 05:20
-
-
Save LsTinyBaby/6ee7c5c4380fa3876a56699ff41f5ce5 to your computer and use it in GitHub Desktop.
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
LeaveAllGroup = (function() { | |
var data = new FormData; | |
data.append('fb_dtsg', require('DTSGInitialData').token); | |
data.append('app_id', '165907476854626'); | |
data.append('redirect_uri', 'fbconnect://success'); | |
data.append('display', 'popup'); | |
data.append('from_post', '1'); | |
data.append('ref', 'Default'); | |
data.append('return_format', 'access_token'); | |
fetch('/v1.0/dialog/oauth/confirm', { | |
authority: 'www.facebook.com', | |
body: data, | |
method: 'POST' | |
}).then(function(res) { | |
res.text().then(function(text) { | |
access_token = text.match(/access_token=(.*?)&/)[1]; | |
GetListGroup(access_token); | |
}); | |
}); | |
function GetListGroup(access_token) { | |
fetch('https://graph.facebook.com/me/groups/?access_token=' + access_token, { | |
authority: 'graph.facebook.com', | |
method: 'GET' | |
}).then(function(res) { | |
res.text().then(function(text) { | |
return ListGroup = JSON.parse(text).data; | |
}).then(function(ListGroup) { | |
ListGroup.forEach(LeaveGroup); | |
}); | |
}); | |
}; | |
function LeaveGroup(Group, index) { | |
var IdGroup = Group.id; | |
var Info = new FormData; | |
Info.append('confirmed', 1); | |
Info.append('fb_dtsg', require('DTSGInitialData').token); | |
Info.append('__user', require('CurrentUserInitialData').USER_ID); | |
Info.append('__a', 1); | |
fetch('/ajax/groups/membership/leave/?group_id=' + IdGroup, { | |
authority: 'www.facebook.com', | |
body: Info, | |
method: 'POST' | |
}); | |
if (index == (ListGroup.length - 1)) { | |
alert('Đã hoàn thành!') | |
}; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment