Facebook Open Graph API Gem for Rails 3.
gem install fbgraph
Be sure to require it
require "fbgraph"
or add this line into Gemfile for Rails 3
gem "fbgraph"
FBGraph supports most (no analytics yet) features of Facebook Open Graph API: developers.facebook.com/docs/reference/api/
IMPORTANT!! Facebook object IDs can be very large numbers—too large to fit in a regular SQL “INTEGER” column. If you use an integer column, your database will likely just store the largest number allowed resulting in a bug that may confound you beyond belief.
IF YOU PLAN TO STORE FACEBOOK GRAPH OBJECT IDS IN YOUR DATABASE, YOU MUST USE A BIGINT COLUMN, NOT A STANDARD INTEGER COLUMN!
Without a token (for authorization)
client = FBGraph::Client.new(:client_id => 'client_id',:secret_id =>'secret_id')
With a token
client = FBGraph::Client.new(:client_id => 'client_id',:secret_id =>'secret_id' ,:token => token)
All methods are chainable
Examples:
client.selection.me.photos.until(Time.now.to_s).since(3.days.ago).limit(10).info!
client.selection.user('id').videos.offset(10).info!
client.search.query('q').on('users').limit(20).info!
returns the authorize url
redirect_to client.authorization.authorize_url(:redirect_uri => callback_url , :scope => 'email,user_photos,friends_photos')
process the callback and returns the access token
access_token = client.authorization.process_callback(params[:code], :redirect_uri => callback_url)
Facebook send a signed_request as a parameter. Can be decoded with the method parse_signed_request of FBGraph::Canvas module
> FBGraph::Canvas.parse_signed_request(app_secret, params[:signed_request])
All objects and their connections can be accesed
Examples:
client.selection.me.home.info!
client.selection.user('id').photos.info!
client.selection.photo('id').comments.info!
client.selection.page('id').info!
Also you can get results of more than 1 objects
Example:
client.selection.user([id1,id2,id3]).info!
request with GET for information and return the response parsed with JSON. You can disable the parsing passing false as a first and unique parameter
user_info = client.selection.me.info!
request with POST for publishing and return the response parsed with JSON. You can disable the parsing passing false as a first and unique parameter
client.selection.post('id').comments.params(:message => 'comment test').publish!
OR
client.selection.post('id').comments.publish!(:message => 'comment test')
request with DELETE for deletion and return the response parsed with JSON. You can disable the parsing passing false as a first and unique parameter
client.selection.post('id').delete!
return the url of the object picture
client.selection.me.picture
client.selection.me.photos.limit(3).info!
client.selection.me.photos.offset(10).info!
client.selection.me.photos.until(Time.now.to_s).info!
client.selection.me.photos.since(3.days.ago).info!
Get the search results
results = client.search.query('facebook').info!
Get the search results by type
results = client.search.query('facebook').on('home').info!
Set the object to be subscribed, modified or unsubscribed
Set the objects fields
Set the callback url
Set the verify token (optional)
Send the request for add/modify a subscription for realtime Updates.
Examples:
results = client.realtime.user.fields('email,picture').callback_url(url).verify_token('token').subscribe!
results = client.realtime.permissions.fields('read_stream').callback_url(url).subscribe!
If you want delete a subscirpition, you can use the delete! method.
Examples:
results = client.realtime.user.delete!
Examples:
results = client.selection.user(USER_ID).payments.info!(:status => STATUS).
results = client.selection.order(ORDER_ID).publish!(:status => STATUS)
Just do a pull request with the repo in sync.