Created
January 31, 2011 08:30
-
-
Save nov/803773 to your computer and use it in GitHub Desktop.
mixi OAuth & Graph API sample
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 'rubygems' | |
require 'active_support/all' | |
require 'oauth2' | |
config = { | |
:mode => :token, | |
:client_id => SET_YOUR_OWN, | |
:client_secret => SET_YOUR_OWN, | |
:redirect_uri => SET_YOUR_OWN, | |
:authorization_code => SET_YOUR_OWN, | |
:access_token => SET_YOUR_OWN, | |
:refresh_token => SET_YOUR_OWN | |
} | |
client = OAuth2::Client.new( | |
config[:client_id], | |
config[:client_secret], | |
:site => 'http://api.mixi-platform.com', | |
:authorize_url => 'https://mixi.jp/connect_authorize.pl', | |
:access_token_url => 'https://secure.mixi-platform.com/2/token' | |
) | |
case config[:mode] | |
when :authorize | |
redirect_uri = client.web_server.authorize_url( | |
:scope => 'r_profile r_voice w_voice' | |
) | |
`open '#{redirect_uri}'` | |
when :token | |
access_token = client.web_server.get_access_token( | |
config[:authorization_code], | |
:redirect_uri => config[:redirect_uri] | |
) | |
puts <<-RESPONSE | |
ACCESS TOKEN: #{access_token.token} | |
REFRESH TOKEN: #{access_token.refresh_token} | |
EXPIRES IN: #{access_token.expires_in} | |
EXPIRES AT: #{access_token.expires_at} | |
RESPONSE | |
when :resouce | |
access_token = OAuth2::AccessToken.new(client, config[:access_token]) | |
response = JSON.parse access_token.get('/2/people/@me/@self') | |
profile = response['entry'] | |
p profile | |
voices = JSON.parse access_token.get("/2/voice/statuses/#{profile['id']}/user_timeline") | |
p voices | |
result = JSON.parse access_token.post('/2/voice/statuses', { | |
:status => 'Test from OAuth client' | |
}) | |
p result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment