Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Facebook Open Graph API in Ruby

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .bundle
Octocat-spinner-32 lib
Octocat-spinner-32 specs
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Manifest
Octocat-spinner-32 README
Octocat-spinner-32 README.textile
Octocat-spinner-32 Rakefile
Octocat-spinner-32 TODO.list
Octocat-spinner-32 VERSION
Octocat-spinner-32 fbgraph.gemspec
README.textile

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/

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!

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

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

Contributors List

Victor Costan

Mark Bates

Florent Guilleux

Jan De Poorter

Thilo-Alexander Ginkel

Matias Käkelä

h4.

Something went wrong with that request. Please try again.