Created
August 31, 2011 19:56
-
-
Save stevejackson/1184539 to your computer and use it in GitHub Desktop.
Grab tagged photos from Facebook Graph API
This file contains 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
# Ruby script to grab photos tagged of yourself on facebook and download them. | |
# Go to the Graph API explorer (http://developers.facebook.com/tools/explorer) | |
# and generate an access token with the permissions you need (user_photos, user_photo_video_tags) | |
# and use that access token here. | |
require 'json' | |
require 'net/http' | |
def fetch(output_dir, username, photo_limit, access_token) | |
url = "https://graph.facebook.com/#{username}/photos?limit=#{photo_limit}&access_token=#{access_token}" | |
uri = URI.parse(URI.encode(url)) | |
http_session = Net::HTTP.new(uri.host, uri.port) | |
http_session.use_ssl = true | |
response = http_session.request(Net::HTTP::Get.new(uri.request_uri)) | |
jsonresult = JSON.parse(response.body) | |
result_data = jsonresult["data"] | |
if result_data.nil? | |
puts "No data to parse. Maybe you've got an invalid access token or uri?" | |
return | |
end | |
for entry in result_data | |
system "wget --directory-prefix='#{output_dir}' #{entry['source']}" | |
end | |
end | |
fetch('my-photos', 'YOUR_FACEBOOK_IDENTIFIER', 2000, 'YOUR_ACCESS_TOKEN') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment