Delete fb test users recursively
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
<?php | |
// jSON URL which should be requested | |
$app_id = 'app id'; | |
// get access token here: | |
// https://graph.facebook.com/oauth/access_token?client_id=<app id>&client_secret=<app secret>&grant_type=client_credentials | |
$app_access_token = 'access token'; | |
$json_url = 'https://graph.facebook.com/v2.1/'.$app_id.'/accounts/test-users?access_token='.$app_access_token; | |
function deleteUsers($endpoint, $app_access_token) { | |
// Initializing curl | |
$ch = curl_init( $endpoint ); | |
// Configuring curl options | |
$options = array( | |
CURLOPT_RETURNTRANSFER => true, | |
); | |
// Setting curl options | |
curl_setopt_array( $ch, $options ); | |
// Getting results | |
$result = curl_exec($ch); // Getting jSON result string | |
$fbusers = json_decode($result, true); | |
if (!isset($fbusers['data'])) { | |
echo "\nlist test users failed?\n", print_r($fbusers, true); | |
} | |
if (count($fbusers['data']===0)) { | |
print_r($fbusers); | |
} | |
echo "\nfb users: ", count($fbusers['data']), " users\n"; | |
foreach($fbusers['data'] as $fbuser) | |
{ | |
if (!isset($fbuser["access_token"])) { | |
$fbuser["access_token"] = $app_access_token; | |
} | |
if (isset($fbuser["id"]) && isset($fbuser["access_token"])) { | |
$testUID = $fbuser["id"]; | |
$access_token = $fbuser["access_token"]; | |
$string = "https://graph.facebook.com/v2.1/$testUID?method=delete&access_token=$access_token"; | |
$nukeCh = curl_init($string); | |
curl_setopt($nukeCh, CURLOPT_CUSTOMREQUEST, 'DELETE'); | |
echo "\n\n",$string, "\n"; | |
curl_exec($nukeCh); | |
} else { | |
echo "Skipped empty uid:\n",print_r($fbuser, true),"\n\n"; | |
} | |
} | |
if (isset($fbusers['paging'])) { | |
//print_r($fbusers['paging']); | |
deleteUsers($endpoint, $app_access_token); | |
} | |
} | |
deleteUsers($json_url, $app_access_token); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment