Created
May 30, 2011 17:19
-
-
Save sneeu/999171 to your computer and use it in GitHub Desktop.
Generates a bunch of Facebook test users, and dumps the values to stdout as CSV.
This file contains hidden or 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
import csv | |
import json | |
import logging | |
import urllib2 | |
import urlparse | |
APP_ID = '' | |
APP_SECRET = '' | |
PERMISSIONS = ['user_about_me', 'email', 'user_events', 'rsvp_event', 'offline_access', 'publish_stream'] | |
AUTH_URL = 'https://graph.facebook.com/oauth/access_token?client_id=%s&client_secret=%s&grant_type=client_credentials' | |
BASE_URL = 'https://graph.facebook.com/%s/accounts/test-users?installed=true&permissions=%s&method=post&access_token=%s' | |
logging.basicConfig(level=logging.INFO) | |
def main(outfile): | |
response = urllib2.urlopen(AUTH_URL % (APP_ID, APP_SECRET)).read() | |
app_access_token = urlparse.parse_qs(response)['access_token'][0] | |
logging.debug(app_access_token) | |
for i in xrange(0, 30): | |
url = BASE_URL % (APP_ID, ','.join(PERMISSIONS), app_access_token) | |
logging.debug(url) | |
response = urllib2.urlopen(url).read() | |
logging.debug(response) | |
doc = json.loads(response) | |
if i == 0: | |
writer = csv.DictWriter(outfile, fieldnames=doc.keys()) | |
writer.writerow(dict(zip(doc.keys(), doc.keys()))) | |
writer.writerow(doc) | |
if __name__ == '__main__': | |
import sys | |
main(sys.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment