Skip to content

Instantly share code, notes, and snippets.

@Houdini
Created April 21, 2011 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Houdini/934046 to your computer and use it in GitHub Desktop.
Save Houdini/934046 to your computer and use it in GitHub Desktop.
facebook connection with oauth2 gem. Works under 1.9.2 and error in ruby 1.8.7
require 'rubygems'
# require 'faraday'
# module Faraday
# class Adapter < Middleware
# def call(env)
# env[:ssl][:verify] = false if env[:ssl]
# process_body_for_request(env)
# end
# end
# end
require 'sinatra'
require 'oauth2'
require 'json'
set :port, 80
def client
OAuth2::Client.new('app_id', 'app_secret', :site => 'https://graph.facebook.com')
end
get '/auth/facebook' do
redirect client.web_server.authorize_url(
:redirect_uri => redirect_uri,
:scope => 'email,offline_access'
)
end
get '/facebook/auth/callback' do
access_token = client.web_server.get_access_token(params[:code], :redirect_uri => redirect_uri)
user = JSON.parse(access_token.get('/me'))
user.inspect
end
def redirect_uri
"your url here"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment