我正试图通过oauth连接到雅虎。我正在使用红宝石的oauth宝石。
我可以成功获取访问令牌,但之后我无法使用它进行任何调用。这是我的代码:
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 :(得分:0)
我正在努力并且即将完成的事情
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=
&amp; T=z=
个cookie然后您现在可以打开一个新的套接字连接到聊天服务,如此
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并登录到那里的聊天服务,我不是一个完整的红宝石程序员但是已经注意到它非常容易使用所以希望这有助于交配。