Skip to content

Latest commit

 

History

History
254 lines (117 loc) · 5.63 KB

README.textile

File metadata and controls

254 lines (117 loc) · 5.63 KB

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 the most (no analytics yet) features of Facebook Open Graph API: developers.facebook.com/docs/reference/api/

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 segned_request as a parameter. Can be decoded with the method parse_signed_request of FBGraph::Canvas module

> FBGraph::Canvas.parse_signed_request(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!

Analytics

TODO

Advanced

not documented yet

Contributions

Just do a pull request with the repo in sync.

Contributors List

Victor Costan

Mark Bates

Florent Guilleux

Jan De Poorter

Thilo-Alexander Ginkel

Matias Käkelä

Matt Lightner