Skip to content

Instantly share code, notes, and snippets.

@simpx
Created March 28, 2012 13:26
Show Gist options
  • Save simpx/2226159 to your computer and use it in GitHub Desktop.
Save simpx/2226159 to your computer and use it in GitHub Desktop.
Weibo Oauth2 use OAuth2 gem
require 'oauth2'
require 'json'
OAuth2::Response.register_parser(:text, 'text/plain') do |body|
parsed_body = JSON.parse(body)
parsed_body
end
client = OAuth2::Client.new(YOU_KEY, YOU_SECRET, :site => "https://api.weibo.com", :authorize_url => "/oauth2/authorize", :token_url => "/oauth2/access_token")
puts client.auth_code.authorize_url(:redirect_uri => YOUR_CALLBACK_URL)
token = client.auth_code.get_token('authorization_code_value', :redirect_uri => YOUR_CALLBACK_URL)
token.options[:header_format] = 'OAuth2 %s'
response = token.get('/2/statuses/public_timeline.json')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment