h2. FBGRaph
-
Facebook Open Graph API Gem for Rails 3.
h2. Resources
-
“View RDoc on RDoc.info”:rdoc.info/projects/nsanta/fbgraph
-
“View Source on GitHub”:github.com/nsanta/fbgraph
-
“Report Issues on GitHub”:github.com/nsanta/fbgraph/issues
h2. Installation
notextile. gem install fbgraph
-
Be sure to require it
notextile. require "fbgraph"
-
or add this line into Gemfile for Rails 3
notextile. gem "fbgraph"
h2. Example Apps
“Rails 3 Example”:github.com/nsanta/fbgraph_example
h2. 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 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
-
Without a token (for authorization)
notextile. client = FBGraph::Client.new(:client_id => 'client_id',:secret_id =>'secret_id')
-
With a token
notextile. client = FBGraph::Client.new(:client_id => 'client_id',:secret_id =>'secret_id' ,:token => token)
-
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
-
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
-
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)
h3. Selection
h4. Accessing objects with connection types.
-
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!
-
Also you can get results of more than 1 objects
Example:
notextile. client.selection.user([id1,id2,id3]).info!
h4. 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
notextile. user_info = client.selection.me.info!
h3. Publishing
h4. 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
notextile. client.selection.post('id').comments.params(:message => 'comment test').publish!
-
OR
notextile. client.selection.post('id').comments.publish!(:message => 'comment test')
h3. Deletion
h4. 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
notextile. client.selection.post('id').delete!
h3. Picture
h4. client.selection.picture
-
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!
-
Get the search results
notextile. results = client.search.query('facebook').info!
h4. client.search.query(‘query’)on(‘type’).info!
-
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
-
Set the object to be subscribed, modified or unsubscribed
h4. client.realtime.fields(‘email,picture’)
-
Set the objects fields
h4. client.realtime.callback_url(url)
-
Set the callback url
h4. client.realtime.verify_token(token)
-
Set the verify token (optional)
h4. client.realtime.subscribe!
-
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
-
Just do a pull request with the repo in sync.
h2. Maintainers
“Nicolas Santa”:github.com/nsanta
“Matt Lightner (via RedRadiant)”:github.com/redradiant
“Victor Costan”:github.com/pwnall
h2. Contributors List
“Mark Bates”:github.com/markbates
“Florent Guilleux”:github.com/Florent2
“Jan De Poorter”:github.com/DefV
“Thilo-Alexander Ginkel”:github.com/ginkel
“Matias Käkelä”:github.com/massive
“Max De Marzi”:github.com/maxdemarzi
“Peter Boling”:github.com/pboling
“Roberto Miranda”:github.com/robertomiranda