How do I connect to Yahoo with oauth using Ruby?
I'm trying to connect to yahoo via oauth. I'm using the oauth gem with ruby.
开发者_如何学GoI can successfully get an access token, but then I'm no able to use it to make any call. Here's my code:
def oauth
OAuth::Consumer.new(ApplicationConfig['yahoo']['access_token'],
ApplicationConfig['yahoo']['secret'],
{
:site => 'https://api.login.yahoo.com',
:scheme => :query_string,
:http_method => :get,
:request_token_path => '/oauth/v2/get_request_token',
:access_token_path => '/oauth/v2/get_token',
:authorize_path => '/oauth/v2/request_auth',
:oauth_callback => 'http://my_callback'
})
end
def oauth_api
OAuth::Consumer.new(ApplicationConfig['yahoo']['access_token'],
ApplicationConfig['yahoo']['secret'],
{
:site => 'http://address.yahooapis.com',
:scheme => :header,
:realm => 'yahooapis.com',
:http_method => :get,
:request_token_path => '/oauth/v2/get_request_token',
:access_token_path => '/oauth/v2/get_token',
:authorize_path => '/oauth/v2/request_auth'
})
end
@request_token = oauth.get_request_token( { :oauth_callback => 'my_callback' } )
# go to @request_token.authorize_url
@access_token = @request_token.get_access_token({ :oauth_verifier => params[:oauth_verifier] })
@access_token.consumer = oauth_api
## Now I have an access token, but if I do something like:
response = @access_token.get('/v1/searchContacts')
## Then I get
#<Net::HTTPForbidden 403 Forbidden readbody=true>
# >> response.body
# => "<!-- web231.address.pim.re3.yahoo.com uncompressed/chunked Wed Jan 13 01:15:46 PST 2010 -->\n"
Basically I would expect that to work.
I've not been able to find any working example on how to connect to yahoo with Ruby. I hope someone else has done this before and he/she's willing to help.
something im working on and just about finished
host = 'login.yahoo.com'#set the host server in this case its login.yahoo.com
port = 80 #self explainitray
path = "/config/login_verify2/ispverify_user?&login=#{username}&passwd=#{password}"
request = "GET #{path} HTTP/1.0\r\n\r\n" # send the HTTP GET request to the server
socket = TCPSocket.open(host,port) # make the connection to the server
socket.puts(request) # send the GET request to the server
data_arrival = socket.read
then split the Y=v=
& T=z=
cookies and then you can now open a new socket to connect to the chat service like so
login_packet = "1À€#{username}À€244À€0À€6À€Y=v=#{ycookie_start,ycookie_end[0]}; T=z=#{tcookie_start,tcookie_end[0]}À€"
chatlogin = "YMSG#{0.chr}#{17.chr}#{0.chr}#{0.chr}#{(login_packet.length / 256).chr}#{(login_packet.length % 256).chr}#{2.chr}#{38.chr}#{0.chr}#{0.chr}#{0.chr}#{0.chr}#{0.chr}#{0.chr}#{0.chr}#{0.chr}#{login_packet}"
socket2 = TCPSocket.open('scs.msg.yahoo.com', 5050)
socket2.puts(chatlogin)
data2 = socket2.read
this isnt complete full woriking client as yet but can get the cookie and also login to there chat service with whats there, i aint a full ruby programmer but have noticed its very easy to work with so hope this helps mate.
精彩评论