Skip to content

Instantly share code, notes, and snippets.

@parris
Last active August 20, 2018 17:52
Show Gist options
  • Save parris/f61273b0962d3af59c864dd7dae39c2d to your computer and use it in GitHub Desktop.
Save parris/f61273b0962d3af59c864dd7dae39c2d to your computer and use it in GitHub Desktop.
Facebook has a 2000 person limit on test users and sometimes you'll consume all of them. There is nothing in the UI that lets you delete all of them. This script will help you do so in an automated way.
/**
* This will delete facebook test users for the specified appId.
* Usage node ./script/dumpFacebookTestUsers.js [appId] [appSecret]
*
* Copyright 2018 Brigade and Parris Khachi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable no-console */
const { Facebook } = require('fb');
const appId = process.argv[2];
const appSecret = process.argv[3];
const fb = new Facebook({
appId,
appSecret,
version: 'v2.12',
});
async function dumpTestUsers() {
const accessTokenResult = await fb.api('oauth/access_token', {
client_id: appId,
client_secret: appSecret,
grant_type: 'client_credentials',
});
fb.setAccessToken(accessTokenResult.access_token);
let testUsers = [];
let after = true;
while (after) {
let result;
if (typeof after === 'string') {
result = await fb.api(`${appId}/accounts/test-users`, { after });
} else {
result = await fb.api(`${appId}/accounts/test-users`);
}
testUsers = testUsers.concat(result.data);
after = result.paging && result.paging.cursors && result.paging.cursors.after;
if (testUsers.count > 3000) {
console.log('There is likely a bug, there should not be more than 2000 test users.');
break;
}
}
console.log(`Found ${testUsers.length} test users.`);
// If this fails, just run the script again and see if everything magically works (thanks FB)
await Promise.all(testUsers.map(user => fb.api(user.id, 'delete')));
}
dumpTestUsers();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment