2010-01-27 28 views
2

我试图通过oauth连接到雅虎。我用红宝石使用oauth宝石。如何使用Ruby连接到使用oauth的Yahoo?

我可以成功获取访问令牌,但是我无法使用它来进行任何调用。这里是我的代码:

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" 

基本上我会希望工作。

我还没找到任何有关如何使用Ruby连接到雅虎的示例。我希望其他人已经做到了,他/她愿意提供帮助。

回答

0

东西IM工作的,只是谈完了

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 

再拆Y=v= & T=z=饼干,那么你现在可以打开一个新的套接字连接到聊天服务,像这样

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 

这还不是一个完整的全面攻击客户端,但可以获取cookie,并且还可以登录到那里的聊天服务,我不是一个完整的ruby程序员,但已经注意到它非常容易与希望一起工作这有助于队友。

相关问题