Skip to content

Instantly share code, notes, and snippets.

@apraditya
Created December 12, 2012 16:29
Show Gist options
  • Save apraditya/4269278 to your computer and use it in GitHub Desktop.
Save apraditya/4269278 to your computer and use it in GitHub Desktop.
A simple ruby script to generate Facebook [Test Users](https://developers.facebook.com/docs/test_users/).
require 'open-uri'
require 'json'
app_id = 'YOUR_FACEBOOK_APP_ID'
app_secret = 'YOUR_FACEBOOK_APP_SECRET'
full_name = 'John Smith'
token_request_url = "https://graph.facebook.com/oauth/access_token?client_id=#{app_id}"
token_request_url += "&client_secret=#{app_secret}&grant_type=client_credentials"
begin
app_access_token = open(token_request_url).read.split('=')[1]
app_access_token = app_access_token.split('|').join('%7C')
full_name = full_name.split(' ').join('%20')
url = "https://graph.facebook.com/#{app_id}/accounts/test-users?installed=true"
url += "&name=#{full_name}&locale=en_US&permissions=read_stream&method=post"
url += "&access_token=#{app_access_token}"
user_attributes = JSON.parse open(url).read
displayed_attributes = ['email', 'password']
if displayed_attributes.all? {|k| user_attributes.keys.include?(k) }
displayed_attributes.each do |attr|
puts "#{attr.capitalize}: #{user_attributes[attr]}"
end
end
rescue Exception => e
puts e.message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment