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 =’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 😀

3 thoughts on “Foursquare API with Ruby

  1. 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?

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.