DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Emad has posted 58 posts at DZone. View Full User Profile

get facebook friends data and save them as json file

03.19.2014
| 2901 views |
  • submit to reddit
#!/usr/bin/env ruby
require 'koala' # gem install koala --no-document
require 'json'
# create a facebook app and get access token from here
# https://developers.facebook.com/tools/explorer
# select "user_friends" when authenticating
oauth_access_token = 'xxxxxxxxxxxxxxxx'

graph = Koala::Facebook::API.new(oauth_access_token)
fields = 'bio,name,birthday,first_name,last_name,gender,hometown,relationship_status,username,website,languages'

friends = []
# getting groups of interest
page = graph.get_connections("me", "friends/?fields=#{fields}")
begin
	friends += page
end while page = page.next_page

# write data to file as json
File.write 'friends.json', friends.to_json