Created
April 21, 2011 09:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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