buy clomid online

Nov 17

Foursquare API with Ruby

Category: foursquare,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
  10.  

For more information :
http://rubygems.org/gems/foursquare-ruby-api

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

3 comments

3 Comments so far

  1. […] This post was mentioned on Twitter by Nihed MBAREK and Houssein, Maghreblogs. Maghreblogs said: [Tunisie] Foursquare API with Ruby: Foursquare now is the most important location-based social network and used … http://bit.ly/dnzsIu […]

  2. Tatiana Carvalho November 25th, 2010 4:08 am

    Hi.

    *newbie question*

    just tried to use this code to test.
    my error:

    in `[]’: can’t convert String into Integer (TypeError)
    from test2.rb:15
    from test2.rb:13:in `each’
    from test2.rb:13

    13 fq.checkins()[‘checkins’][‘checkin’].each do |f|
    15 puts f[‘display’]+ ‘ ‘ + f[‘created’]

    do u have more examples using this GEM?
    thanks!

  3. nihed November 28th, 2010 9:42 am

    can you try to change ‘ ‘ to ” ” on line 15 .

Leave a comment