Tuesday, December 28, 2010

facebook graph api in ruby on rails application


TO SEARCH FACEBOOK POSTS IN RUBY ON RAILS WITH FGRAPH
Introduction :
Facebook Graph Ruby API implementation with Ruby magic (graph.facebook.com).
You can apply all options available with facebook graph API in your application.
Installation : script/plugin install http://github.com/jugend/fgraph.git
Benifits:
To use graph.facebook API in your application.
Allow to search any keyword or posts from facebook.
Allow to publish your posts.
You can fire single and multi object query.
The follwing steps will give you idea about using fgraph for searching posts from facebook.
Step1: Before starting you have to add facebook registered app_key and secrete key in your fgraph.yml file.
Step2: In controller or in your application’s console write following query.
FGraph.search(‘watermelon’, :type => ‘post’)
OR
FGraph.search_post('watermelon')
Example:
>> @fb_post = FGraph.search_post(‘PAC-MAN’,:limit=>2)
=> [{"name"=>"FUNNY!!! The Funniest Boxing Bout Ever!!!", "from"=>{"name"=>"Rodelio Vergara", "id"=>"100000696510058"}, "application"=>{"name"=>"Links", "id"=>"2309869772"}, "icon"=>"http://static.ak.fbcdn.net/rsrc.php/yj/r/v2OnaTyTQZE.gif", "id"=>"100000696510058_164141430295647", "created_time"=>"2010-12-20T08:29:58+0000", "type"=>"video", "caption"=>"www.youtube.com", "updated_time"=>"2010-12-20T08:29:58+0000", "description"=>"Ladies and gentlemen, place ur bets cos this is the funniest fighting bout ever in the history of mankind. Laugh, comment n rate. Enjoy!!!", "link"=>"http://www.youtube.com/watch?v=atcOdlj6aQI", "source"=>"http://www.youtube.com/v/atcOdlj6aQI&autoplay=1", "message"=>"ito ang tatalo kay pacman!!", "picture"=>"http://external.ak.fbcdn.net/safe_image.php?d=9d9ef62897b0b3a6bec50451a530c99a&w=130&h=130&url=http%3A%2F%2Fi.ytimg.com%2Fvi%2FatcOdlj6aQI%2F0.jpg"}, {"name"=>"TrackRunners - Pacman The Best Pound for Pound [HD]“, “from”=>{“name”=>”Yeyeng Espiritu”, “id”=>”100000679937927″}, “application”=>{“name”=>”Links”, “id”=>”2309869772″}, “icon”=>”http://static.ak.fbcdn.net/rsrc.php/yD/r/aS8ecmYRys0.gif”, “id”=>”100000679937927_175007109186972″, “created_time”=>”2010-12-20T08:28:52+0000″, “type”=>”video”, “updated_time”=>”2010-12-20T08:28:52+0000″, “description”=>”Pacman Going Global .”, “link”=>”http://www.facebook.com/video/video.php?v=247590965601&comments”, “source”=>”http://video.ak.fbcdn.net/video-ak-sf2p/v6812/145/0/247590965601_14126.mp4?h=855c4a747638f225068a4c02d91e29aa&r=2060&__gda__=1293006640_a92b81d80f0e4463e8272d2eaa4c075f”, “properties”=>[{"name"=>"Length", "text"=>"4:13"}], “picture”=>”http://vthumb.ak.fbcdn.net/vthumb-ak-ash1/v2673/48/57/582600601/t582600601_247590965601_1820.jpg“}]
You can test this on
https://graph.facebook.com/search?q=watermelon&type=post
Step 3:To publish your post
FGraph.publish('arjun/feed', :message => 'Hello, Arjun. I like this n  ew API.',
:access_token => '...')
FGraph.publish_feed('arjun', :message => '...', :access_token => '... ')
FGraph.publish_feed('me', :message => '...', :access_token => '...')
For more options , please check on github

No comments:

Post a Comment