Created
February 28, 2011 16:16
-
-
Save tbaba/847536 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require 'rubygems' | |
require 'oauth2' | |
require 'sinatra' | |
require 'json' | |
API_KEY = your_api_key | |
API_SECRET = your_api_secret | |
class Facebook | |
def initialize(key, secret) | |
@key, @secret = key, secret | |
end | |
def client | |
OAuth2::Client.new(@key, @secret, :site => "https://graph.facebook.com") | |
end | |
def redirect_uri | |
uri = URI.parse(request.url) | |
uri.path = '/auth/facebook/callback' | |
uri.query = nil | |
uri.to_s | |
end | |
end | |
get '/auth/facebook' do | |
client = Facebook.new(API_KEY, API_SECRET) | |
redirect client.web_server.authorize_url(:redirect_uri => redirect_uri) | |
end | |
get '/auth/facebook/callback' do | |
access_token = client.web_server.access_token(params[:code], :redirect_uri => redirect_uri) | |
user = JSON.parse(access_token.get('/me')) | |
user.inspect | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
試しに書いてみた。多分動かない。