Created
July 21, 2011 21:02
-
-
Save paulwalker/1098192 to your computer and use it in GitHub Desktop.
oauth2 => facebook example
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
require 'rubygems'; require 'spec/helper'; Faraday.default_adapter = :net_http | |
args = { :site => 'https://graph.facebook.com', :token_url => '/oauth/access_token', :ssl => { :verify => false } } | |
client = OAuth2::Client.new('155938287786939', '7e3f065e969f7c499bcda855b98e0989', args) | |
redirect_uri = 'https://github.com/paulwalker/oauth2/' | |
client.auth_code.authorize_url(:redirect_uri => redirect_uri) | |
# https://graph.facebook.com/oauth/authorize?response_type=code&client_id=155938287786939&redirect_uri=https%3A%2F%2Fgithub.com%2Fpaulwalker%2Foauth2%2F | |
# navigate to domain in browser and then put code value in | |
code = '' | |
begin; token = client.auth_code.get_token(code, :redirect_uri => redirect_uri, :parse => :query); rescue Exception => e; end | |
token.options.merge!(:header_format => 'OAuth %s', :param_name => 'access_token') | |
begin; response = token.get('/me', :parse => :json); rescue Exception => e; end | |
response.parsed | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment