Facebook Graph with Ruby

The Open Graph protocol enables developers to integrate their pages into the social graph. These pages gain the functionality of other graph objects including profile links and stream updates for connected users. Documentations for facebook api are available on this link.
Ruby offer a library to communicate with Facebook Graph named “rfgraph”.
To install :

  1. $ sudo gem install rfgraph

Next, you can write your code. We will use this library to retrieve user information for a range of id. For this, we will create a loop from 610552189 ( my id) to 610552219 (another id) and show available information :

  1. require ‘rubygems’
  2. require ‘rfgraph’
  4. req = RFGraph::Request.new
  6. for i in 610552189..610552219 do
  7.   begin
  8.     res= req.get_object(i)
  9.     puts "#{res[‘id’]} #{res[‘name’]} #{res[‘first_name’]} #{res[‘last_name’]}"+
  10.       " #{res[‘gender’]} #{res[‘locale’]} #{res[‘link’]}"
  11.   rescue Exception=>e
  12.   end
  13. end

and the result will be :

  1. 610552189 Nihed Mbarek Nihed Mbarek male fr_FR http://www.facebook.com/nihed.mbarek
  2. 610552198 Stephanie Pedrin Stephanie Pedrin  es_LA http://www.facebook.com/stephanie.pedrin
  3. 610552201 Roz Rossington Roz Rossington female en_GB http://www.facebook.com/people/Roz-Rossington/610552201
  4. 610552204 Timbucktwo Hair Timbucktwo Hair  en_US http://www.facebook.com/people/Timbucktwo-Hair/610552204
  5. 610552207 Arkoun Merchant Arkoun Merchant male en_US http://www.facebook.com/arkoun
  6. 610552210 Gulcin Takmaz Gulcin Takmaz female en_GB http://www.facebook.com/people/Gulcin-Takmaz/610552210
  7. 610552213 Lara Mezzanotte Lara Mezzanotte  en_US http://www.facebook.com/people/Lara-Mezzanotte/610552213
  8. 610552217 Kita Collier-Smith Kita Collier-Smith female en_US http://www.facebook.com/people/Kita-Collier-Smith/610552217

For more information :

PS : I hope that facebook block user that try to retreive a large number of information.

1 thought on “Facebook Graph with Ruby

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.