Created
June 3, 2013 03:54
-
-
Save jhurliman/5696050 to your computer and use it in GitHub Desktop.
Dump recent Facebook profile info, likes, photos, and posts to JSON text files
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 urllib2 | |
import json | |
FB_TOKEN = '...' | |
MAX_PAGES = 10 | |
def scrape_page(page): | |
all_data = [] | |
url = ('https://graph.facebook.com' + page + '?limit=50&access_token=' + | |
FB_TOKEN) | |
current_page = 1 | |
while current_page <= MAX_PAGES: | |
response = urllib2.urlopen(url) | |
data = response.read() | |
json_data = json.loads(data) | |
print 'Fetched ' + page + ' page ' + str(current_page) | |
current_page += 1 | |
if 'username' in json_data: | |
return json_data | |
if 'data' in json_data: | |
all_data.extend(json_data['data']) | |
else: | |
print 'ERROR:' | |
print json_data | |
break | |
if 'paging' in json_data and 'next' in json_data['paging']: | |
url = json_data['paging']['next'] | |
else: | |
break | |
return all_data | |
def write_data(data, filename): | |
with open(filename, 'w') as outfile: | |
json.dump(data, outfile) | |
write_data(scrape_page('/me'), 'about.txt') | |
write_data(scrape_page('/me/likes'), 'likes.txt') | |
write_data(scrape_page('/me/photos'), 'photos.txt') | |
write_data(scrape_page('/me/posts'), 'posts.txt') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried it but it's not working. Or does it only works on the profiles those are not locked?