Created
November 19, 2014 19:29
-
-
Save juanjoseijas/707b1cfb0b8dd8d45e5d to your computer and use it in GitHub Desktop.
Using HTTParty To Fetch Facebook
This file contains hidden or 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
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