Skip to content

Instantly share code, notes, and snippets.

@johnbender
Created September 18, 2009 21:49
Show Gist options
  • Save johnbender/189316 to your computer and use it in GitHub Desktop.
Save johnbender/189316 to your computer and use it in GitHub Desktop.
require 'myspace'
require 'pp'
#CONSUMER/SECRET removed
#our "session"
session = {}
#Build our consumer
myspace = MySpace::MySpace.new(CONSUMER_KEY, CONSUMER_SECRET)
#req token
request_token = myspace.get_request_token
#get the auth url
auth_url = myspace.get_authorization_url(request_token, 'http://yourcallback.com/')
#save the token in our "session"
session[:unauthed_token] = {:token => request_token.token, :secret => request_token.secret}
#open the url in a browser
`open '#{auth_url}'`
#wait for the user to come back from the browser
gets
#assuming the authorization has been approved get the information
myspace = MySpace::MySpace.new(CONSUMER_KEY, CONSUMER_SECRET,
:request_token => session[:unauthed_token][:token],
:request_token_secret => session[:unauthed_token][:secret])
#get our access token since were authorized
access_token = myspace.get_access_token
#store it for later use
session[:authed_token] = {:token => access_token.token, :secret => access_token.secret}
#get the user id for later queries
user_id = myspace.get_userid
#Get the profile data
profile_data = myspace.get_profile(user_id)
friends_data = myspace.get_friends(user_id)
#print our data
pp user_id
pp profile_data
pp friends_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment