Created
April 28, 2009 00:23
-
-
Save boscomonkey/102845 to your computer and use it in GitHub Desktop.
This file contains 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/consumer' | |
# need to define methods: app_name, developer_key, developer_secret | |
consumer = OAuth::Consumer.new(developer_key, | |
developer_secret, | |
:site => "http://api.netflix.com", | |
:request_token_url => "http://api.netflix.com/oauth/request_token", | |
:access_token_url => "http://api.netflix.com/oauth/access_token", | |
:authorize_url => "https://api-user.netflix.com/oauth/login") | |
request_token = consumer.get_request_token | |
# (optional) :oauth_callback => redirect_url | |
url = request_token.authorize_url(:oauth_consumer_key => developer_key, | |
:application_name => app_name) | |
`firefox -url "#{url}"` | |
# wait until you're done with firefox; otherwise, access token will be nil | |
access_token = request_token.get_access_token | |
# xml | |
response = access_token.get "/users/#{access_token.params[:user_id]}" | |
xml = response.body | |
# JSON | |
response = access_token.get "/users/#{access_token.params[:user_id]}?output=json" | |
json = response.body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For this to work for me, you need to pass the info from the firefox auth page into get_access_token. So replace line 18 with the following:
print "Enter pin: "
pin = gets.chomp
access_token = request_token.get_access_token(:oauth_verifier => pin)