Skip to content

Instantly share code, notes, and snippets.

@juanjoseijas
Created November 19, 2014 19:29
Show Gist options
  • Save juanjoseijas/707b1cfb0b8dd8d45e5d to your computer and use it in GitHub Desktop.
Save juanjoseijas/707b1cfb0b8dd8d45e5d to your computer and use it in GitHub Desktop.
Using HTTParty To Fetch Facebook
require 'rubygems'
require 'httparty'
## define class
class Facebook
## load and inherit HTTParty class
include HTTParty
## set the default base URI
base_uri 'https://graph.facebook.com'
## set the format to JSON, so that HTTParty will automatically decode it
format :json
## constructor
def initialize(access_token)
@access_token = access_token
end
def get_info
self.class.get('/me',:query => { :access_token => @access_token })
end
end
## create an instance of the Facebook class
fb = Facebook.new(<your-access-token>);
## call the method
r = fb.get_info()
print r.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment