Skip to content

Instantly share code, notes, and snippets.

@ardbytes
Created February 28, 2011 13:31
Show Gist options
  • Save ardbytes/847313 to your computer and use it in GitHub Desktop.
Save ardbytes/847313 to your computer and use it in GitHub Desktop.
Get your Yahoo! contacts through Yahoo OAuth on the command line
require "oauth"
@consumer_key = <your-consumer-key>
@consumer_secret = <your-consumer-secret>
@consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret,
{
:site => 'https://api.login.yahoo.com',
:request_token_path => '/oauth/v2/get_request_token',
:access_token_path => '/oauth/v2/get_token',
:authorize_path => '/oauth/v2/request_auth',
:signature_method => 'HMAC-SHA1',
:oauth_version => '1.0'
})
@request_token = @consumer.get_request_token(
{:oauth_callback => 'oob'}
)
p @request_token
# visit @request_token.options[:xoauth_request_auth_url] using a browser and enter
# the code returned below
@oauth_verifier = gets.chomp!
@access_token = @request_token.get_access_token(:oauth_verifier => @oauth_verifier)
puts ""
p @access_token
@response = @access_token.request(:get, 'http://social.yahooapis.com/v1/user/' + @access_token.params[:xoauth_yahoo_guid] + '/contacts', { 'Content-Type' => 'application/xml' })
puts "Response:"
p @response.body # your Yahoo! mail contacts in XML
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment