nsanta / fbgraph

Facebook Open Graph API in Ruby
MIT License
324 stars 40 forks source link

h2. FBGRaph

p. Facebook Open Graph API Gem for Rails 3.

h2. Resources

h2. Installation

notextile. gem install fbgraph

p. Be sure to require it

notextile. require "fbgraph"

p. or add this line into Gemfile for Rails 3

notextile. gem "fbgraph"

h2. Example Apps

"Rails 3 Example":http://github.com/nsanta/fbgraph_example

h2. Usage

p. 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!

h3. Initialization

p. Without a token (for authorization)

notextile. client = FBGraph::Client.new(:client_id => 'client_id',:secret_id =>'secret_id')

p. With a token

notextile. client = FBGraph::Client.new(:client_id => 'client_id',:secret_id =>'secret_id' ,:token => token)

p. All methods are chainable

Examples:

notextile. client.selection.me.photos.until(Time.now.to_s).since(3.days.ago).limit(10).info!

notextile. client.selection.user('id').videos.offset(10).info!

notextile. client.search.query('q').on('users').limit(20).info!

h3. Rails config file

h2. TODO

h3. Authorization

h4. client.authorization.authorize_url

p. returns the authorize url

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

h4. client.authorization.process_callback

p. process the callback and returns the access token

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

h3. Exchange Sessions

h2. TODO

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

h3. Selection

h4. Accessing objects with connection types.

p. All objects and their connections can be accesed

Examples:

notextile. client.selection.me.home.info!

notextile. client.selection.user('id').photos.info!

notextile. client.selection.photo('id').comments.info!

notextile. client.selection.page('id').info!

p. Also you can get results of more than 1 objects

Example:

notextile. client.selection.user([id1,id2,id3]).info!

h4. client.selection.info!

p. 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

notextile. user_info = client.selection.me.info!

h3. Publishing

h4. client.selection.publish!

p. 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

notextile. client.selection.post('id').comments.params(:message => 'comment test').publish!

p. OR

notextile. client.selection.post('id').comments.publish!(:message => 'comment test')

h3. Deletion

h4. client.selection.delete!

p. 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

notextile. client.selection.post('id').delete!

h3. Picture

h4. client.selection.picture

p. return the url of the object picture

notextile. client.selection.me.picture

h3. Paging

h4. client.selection.limit

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

h4. client.selection.offset

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

h4. client.selection.until

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

h4. client.selection.since

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

h3. Search

h4. client.search.query('query').info!

p. Get the search results

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

h4. client.search.query('query')on('type').info!

p. Get the search results by type

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

h3. RealTime Updates

h4. client.realtime.user

h4. client.realtime.permissions

h4. client.realtime.errors

p. Set the object to be subscribed, modified or unsubscribed

h4. client.realtime.fields('email,picture')

p. Set the objects fields

h4. client.realtime.callback_url(url)

p. Set the callback url

h4. client.realtime.verify_token(token)

p. Set the verify token (optional)

h4. client.realtime.subscribe!

p. Send the request for add/modify a subscription for realtime Updates.

Examples:

notextile. results = client.realtime.user.fields('email,picture').callback_url(url).verify_token('token').subscribe!

notextile. results = client.realtime.permissions.fields('read_stream').callback_url(url).subscribe!

If you want delete a subscirpition, you can use the delete! method.

Examples:

notextile. results = client.realtime.user.delete!

h3. FQL

h4. client.fql.query("SELECT name FROM user WHERE uid = me()")

h3. Timeline

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

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

h3. Analytics

h4. TODO

h3. Advanced

h4. not documented yet

h2. Credits

Examples:

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

notextile. results = client.selection.order(ORDER_ID).publish!(:status => STATUS)

h2. Contributions

p. Just do a pull request with the repo in sync.

h2. Maintainers

"Nicolas Santa":http://github.com/nsanta

"Matt Lightner (via RedRadiant)":http://github.com/redradiant

"Victor Costan":http://github.com/pwnall

h2. Contributors List

"Mark Bates":http://github.com/markbates

"Florent Guilleux":http://github.com/Florent2

"Jan De Poorter":http://github.com/DefV

"Thilo-Alexander Ginkel":http://github.com/ginkel

"Matias Käkelä":http://github.com/massive

"Max De Marzi":http://github.com/maxdemarzi

"Peter Boling":https://github.com/pboling

"Roberto Miranda":https://github.com/robertomiranda