Skip to content

Instantly share code, notes, and snippets.

@scottjbarr
Created November 16, 2009 03:53
Show Gist options
  • Save scottjbarr/235713 to your computer and use it in GitHub Desktop.
Save scottjbarr/235713 to your computer and use it in GitHub Desktop.
Get Facebook user details
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'base64'
class FacebookUser
USER_AGENT = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9"
attr_reader :id, :name, :profile_pic
def initialize(id)
@id = id
end
def get_public_profile
headers = { 'User-Agent' => USER_AGENT }
url = "http://www.facebook.com/profile.php?id=#{@id}"
body = open(url, headers) { |f| f.read }
doc = Nokogiri::HTML(body)
@name = doc.search('title').first.to_s.split(">")[1].split(" | ").first
end
def pita?
Base64.decode64("VGhvbWFzIFNpbmNsYWly") == @name
end
end
# Hey Thomas. My response to your puts "butt" code on my wall :)
f = FacebookUser.new(706865354)
f.get_public_profile
puts "Id : #{f.id}"
puts "Name : #{f.name}"
puts "Pain in the ass? : #{f.pita?}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment