Created
March 24, 2014 20:41
-
-
Save etuchscherer/9748694 to your computer and use it in GitHub Desktop.
Script for mass uploading images to Facebook test users profiles.
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
# This script gets test users' access tokens, and | |
# uploads public images to those accounts | |
# At the time of this writing, it takes an input file ( of facebook UIDs ) | |
# an queries an external JSON file for those users ( filtering ). The remaining | |
# filtered users will have images uploaded to their profiles, via the graph | |
# api. | |
require "json"; | |
require "rest-client" | |
# ======================= | |
# ==== Configuration ==== | |
# ======================= | |
graph_api = "https://graph.facebook.com/" | |
# Your apps access token. This is used to retrieve test | |
# users' access tokens. | |
access_token = "<APP_ACCESS_TOKEN>" | |
# Folder containing images to be uploaded | |
image_bucket = "/Users/eric.tuchscherer/headshots/" | |
# The input file is a json list of test user objects. | |
# Users are under the "data" key. | |
# | |
# Example: | |
# { | |
# "data": [ | |
# { | |
# "id": "123456789", | |
# "access_token": "a;sdlkfjdsdsfasdf...", | |
# "login_url": "http://developers.facebook.com/checkpoint/test-user-login/123456789/" | |
# }, | |
# { | |
# "id": "987654321", | |
# "access_token": "sadjhkfgasdoaisud...", | |
# "login_url": "http://developers.facebook.com/checkpoint/test-user-login/987654321/" | |
# }... ect | |
# | |
input_file = "/Users/eric.tuchscherer/json.js" | |
# The filter file is a list of test user ids. This is used to | |
# remove unwanted test users from the filtered list | |
# | |
# Example: | |
# 123456789 | |
# 987654321 | |
# ect | |
filter_file = "/Users/eric.tuchscherer/filters" | |
# ======================= | |
# ======== begin ======== | |
# ======================= | |
# Load all users' JSON data | |
all_test_users = JSON.parse(IO.read(input_file)) | |
# Using these ids only | |
working_ids = IO.readlines(filter_file).map { |l| l.chomp } | |
# The actual list of users to work with | |
working_list = all_test_users["data"] | |
# filter working_list array | |
filtered_data = working_list.keep_if { |x| filters.include? x["id"] } | |
# generate urls to upload photos. | |
filtered_data.each do |d| | |
url = "#{graph_api}#{d["id"]}/photos?access_token=#{d["access_token"]}" | |
random_image = "#{image_bucket}/a#{rand(2..261)}.jpg" | |
RestClient.post(url, { image: File.new(random_image, 'rb') }) do |res, req, ret, &block| | |
puts res + "\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Eric... if you ever get time, mix in Thor, and package this as a gem.