Skip to content

Instantly share code, notes, and snippets.

@yohfee
Created January 27, 2011 15:32
Show Gist options
  • Select an option

  • Save yohfee/798643 to your computer and use it in GitHub Desktop.

Select an option

Save yohfee/798643 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'open-uri'
require 'json'
OAUTH_URL = 'https://foursquare.com/oauth2'
BASE_URL = 'https://api.foursquare.com/v2'
REDIRECT_URI = 'http://localhost:9292/auth'
CLIENT_ID = 'YOUR_CLIENT_ID'
CLIENT_SECRET = 'YOUR_CLIENT_SECRET'
get '/' do
redirect %(#{OAUTH_URL}/authenticate?client_id=#{CLIENT_ID}&response_type=code&redirect_uri=#{REDIRECT_URI})
end
get '/auth' do
res = open(%(#{OAUTH_URL}/access_token?client_id=#{CLIENT_ID}&client_secret=#{CLIENT_SECRET}&grant_type=authorization_code&redirect_uri=#{REDIRECT_URI}/auth&code=#{params['code']}))
json = JSON.parse(res.string)
$token = json['access_token']
redirect '/checkins'
end
get '/checkins' do
res = open(%(#{BASE_URL}/users/self/checkins?oauth_token=#{$token}))
json = JSON.parse(res.read)
json.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment