forked from facebook/facebook-ios-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rm_test_users.py
executable file
·66 lines (57 loc) · 2.02 KB
/
rm_test_users.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
#
# Copyright 2012 Facebook
#
# 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.
#
import sys
import json
import httplib
from urlparse import urlparse
if len(sys.argv) == 3:
appId = sys.argv[1];
appSecret = sys.argv[2];
print("Deleting test users for app " + appId);
else:
print("Must specify appId and appSecret.");
exit(-1);
host = "graph.facebook.com";
fmtGet = "/{0}/accounts/test-users?access_token={0}|{1}";
fmtDel = "/{0}?method=delete&access_token={1}|{2}";
usersPath = fmtGet.format(appId, appSecret);
while usersPath:
print("Getting users via: " + usersPath);
conn = httplib.HTTPSConnection(host);
conn.request("GET", usersPath);
users = json.loads(conn.getresponse().read());
print "Got", len(users["data"]), "users.";
for user in users["data"]:
print("Deleting user {0}".format(user["id"]));
delPath = fmtDel.format(user["id"], appId, appSecret);
conn = httplib.HTTPSConnection(host);
conn.request("GET", delPath);
deleteResult = conn.getresponse().read();
if (deleteResult <> "true"):
print("delete failed, got " + deleteResult);
if not "paging" in users:
break;
paging = users["paging"];
if not "next" in users["paging"]:
break;
nextUrl = paging["next"];
prefix = "https://graph.facebook.com";
if not nextUrl.startswith(prefix):
print("Paging url does not start with "+prefix);
break;
usersPath = nextUrl[len(prefix):];
print("Continuing next page at: " + usersPath);