Created
July 4, 2012 07:19
-
-
Save ilstar/3045866 to your computer and use it in GitHub Desktop.
douban oauth
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 'oauth' | |
require 'oauth/consumer' | |
api_key = "xx" | |
api_key_secret = "xx" | |
consumer = OAuth::Consumer.new( | |
api_key, | |
api_key_secret, | |
{ | |
:site=>"http://www.douban.com", | |
:request_token_path=>"/service/auth/request_token", | |
:access_token_path=>"/service/auth/access_token", | |
:authorize_path=>"/service/auth/authorize", | |
:signature_method=>"HMAC-SHA1", | |
:scheme=>:header, | |
:realm=>"http://yourwebsite.com" | |
} | |
) | |
request_token = consumer.get_request_token | |
puts request_token.authorize_url | |
# waiting user authorization on web page. | |
gets | |
access_token = request_token.get_access_token | |
p access_token | |
access_token = OAuth::AccessToken.new( | |
OAuth::Consumer.new( | |
api_key, | |
api_key_secret, | |
{ | |
site: "http://api.douban.com", | |
scheme: :header, | |
signature_method: "HMAC-SHA1", | |
realm: "http://yourwebsite.com" | |
} | |
), | |
access_token.token, | |
access_token.secret | |
) | |
p access_token.get '/people/%40me' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment