Skip to content

Instantly share code, notes, and snippets.

@boscomonkey
Created April 28, 2009 00:23
Show Gist options
  • Save boscomonkey/102845 to your computer and use it in GitHub Desktop.
Save boscomonkey/102845 to your computer and use it in GitHub Desktop.
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
@kookjr
Copy link

kookjr commented May 1, 2011

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment