Skip to content

Instantly share code, notes, and snippets.

@ilstar
Created July 4, 2012 07:19
Show Gist options
  • Save ilstar/3045866 to your computer and use it in GitHub Desktop.
Save ilstar/3045866 to your computer and use it in GitHub Desktop.
douban oauth
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