Skip to content

nsanta/fbgraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FBGRaph

Facebook Open Graph API Gem for Rails 3.

Resources

Installation

gem install fbgraph

Be sure to require it

require "fbgraph"

or add this line into Gemfile for Rails 3

gem "fbgraph"

Example Apps

Rails 3 Example

Usage

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 SQLINTEGER” 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!

Initialization

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!

Rails config file

TODO

Authorization

client.authorization.authorize_url

returns the authorize url

redirect_to client.authorization.authorize_url(:redirect_uri => callback_url , :scope => 'email,user_photos,friends_photos')

client.authorization.process_callback

process the callback and returns the access token

access_token = client.authorization.process_callback(params[:code], :redirect_uri => callback_url)

Exchange Sessions

TODO

Canvas

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])

Selection

Accessing objects with connection types.

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!

client.selection.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!

Publishing

client.selection.publish!

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')

Deletion

client.selection.delete!

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!

Picture

client.selection.picture

return the url of the object picture

client.selection.me.picture

Paging

client.selection.limit

client.selection.me.photos.limit(3).info!

client.selection.offset

client.selection.me.photos.offset(10).info!

client.selection.until

client.selection.me.photos.until(Time.now.to_s).info!

client.selection.since

client.selection.me.photos.since(3.days.ago).info!

Search

client.search.query(‘query’).info!

Get the search results

results = client.search.query('facebook').info!

client.search.query(‘query’)on(‘type’).info!

Get the search results by type

results = client.search.query('facebook').on('home').info!

RealTime Updates

client.realtime.user

client.realtime.permissions

client.realtime.errors

Set the object to be subscribed, modified or unsubscribed

client.realtime.fields(‘email,picture’)

Set the objects fields

client.realtime.callback_url(url)

Set the callback url

client.realtime.verify_token(token)

Set the verify token (optional)

client.realtime.subscribe!

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!

FQL

client.fql.query(“SELECT name FROM user WHERE uid = me()”)

Timeline

client.timeline.action(‘namespace’, ‘run’).param(:location => [location object URL])

client.timeline.reads.param(:article => [article object URL] )

Analytics

TODO

Advanced

not documented yet

Credits

Examples:

results = client.selection.user(USER_ID).payments.info!(:status => STATUS). results = client.selection.order(ORDER_ID).publish!(:status => STATUS)

Contributions

Just do a pull request with the repo in sync.

Maintainers

Nicolas Santa

Matt Lightner

Victor Costan

Contributors List

Mark Bates

Florent Guilleux

Jan De Poorter

Thilo-Alexander Ginkel

Matias Käkelä

Max De Marzi

Peter Boling

Roberto Miranda

About

Facebook Open Graph API in Ruby

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages