2010-01-27 39 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程序員,但已經注意到它非常容易與希望一起工作這有助於隊友。

相關問題