|\| | |-| € [)

Month: November 2010

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.

Foursquare API with Ruby

Foursquare now is the most important location-based social network and used by many of my contacts. And Ruby, like for every social network offer libraries that can help developer to be more productive. Foursquare is now available as an API using basic authentication or Oauth, for more information documentation.
For Library, GEM’s are available, one of them “foursquare-ruby-api” can do for you what you want.
To install :

  1. $ sudo gem install foursquare-ruby-api

Next, you can write your code to do what you want.
To begin this sample, we must know some useful methods :

  • Checkins : Returns a list of recent checkins from friends.
  • Check-in : Allows you to check-in to a place.
  • History : Returns a history of checkins for the authenticated user.

For more information, Very rich documentation are available with ideas about parameters and results structures.
And our Example will be a list of recent checkins from our friends:

  1. require ‘rubygems’
  2. gem (‘foursquare-ruby-api’)
  3. require ‘foursquare’
  4. fq = Foursquare.new(’email’,‘password’)
  5. # fq.test is optional to test our connexion
  6. fq.test
  7. fq.checkins()[‘checkins’][‘checkin’].each do |f|
  8.    puts f[‘display’]+"   "+f[‘created’]
  9. end

For more information :

PS: This api can be used as a hack to be mayor for many places from your house or office 😀

Twitter Search with Ruby

Ruby is one of the most powerful language with the number of GEM’s (Packages) that can be used to connect on every component of internet.
For twitter, GEM’s are available, one of them “twitter” can do for you what you want.
To install :

  1. $ sudo gem install twitter

Next, you can write your code to do what you want (Search for our example) .
To begin this sample, we must know some useful option for search :

  • from(“XXXX”) : to define the sender of our messages
  • to(“XXXX”) : to define the receiver of our messages
  • since_date(“YYYY-MM-DD”) : to get tweets after a given date

For more information : http://rdoc.info/github/jnunemaker/twitter/master/Twitter/Search
And our code will be :

  1. require ‘rubygems’
  2. require ‘twitter’
  3. #search for the word nihed since 01/11/2010
  4. Twitter::Search.new(‘nihed’).since_date("2010-11-01").each do |r|
  5.   puts r.from_user+": "+r.text+"\n\n"
  6. end

Like we can see, with ruby, we have a simple and beautiful code.
For more information :
Twitter Search API Method

Copyright © 2018 |\| | |-| € [)

Theme by Anders NorenUp ↑