如何使用Ruby通过oauth连接到Yahoo?

如何使用Ruby通过oauth连接到Yahoo?,ruby,oauth,Ruby,Oauth,我正试图通过oauth连接到雅虎。我将oauth gem与ruby一起使用 我可以成功地获得访问令牌,但是我无法使用它进行任何呼叫。这是我的密码: def oauth OAuth::Consumer.new(ApplicationConfig['yahoo']['access_token'], ApplicationConfig['yahoo']['secret'], { :site => 'htt

我正试图通过oauth连接到雅虎。我将oauth gem与ruby一起使用

我可以成功地获得访问令牌,但是我无法使用它进行任何呼叫。这是我的密码:

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"
def oauth
OAuth::Consumer.new(ApplicationConfig['yahoo']['access\u token'],
ApplicationConfig['yahoo']['secret'],
{
:site=>'https://api.login.yahoo.com', 
:scheme=>:查询字符串,
: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'
})
结束
def oauth_api
OAuth::Consumer.new(ApplicationConfig['yahoo']['access\u token'],
ApplicationConfig['yahoo']['secret'],
{
:site=>'http://address.yahooapis.com', 
:scheme=>:标题,
:realm=>'yahooapi.com',
:http_method=>:get,
:request_token_path=>'/oauth/v2/get_request_token',
:access_token_path=>'/oauth/v2/get_token',
:authorize\u path=>'/oauth/v2/request\u auth'
})
结束
@request\u token=oauth.get\u request\u token({:oauth\u callback=>'my\u callback'})
#转到@request\u token.authorize\u url
@access_-token=@request_-token.get_-access_-token({:oauth_-verifier=>params[:oauth_-verifier]})
@access_token.consumer=oauth_api
##现在我有了一个访问令牌,但如果我执行以下操作:
response=@access\u token.get('/v1/searchContacts')
##然后我得到
#
#>>response.body
#=>“\n”
基本上,我认为这是可行的


我还没有找到任何关于如何使用Ruby连接到yahoo的工作示例。我希望其他人以前也这样做过,他/她愿意帮忙。

我正在做的事情,即将完成

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=
cookies,然后您现在可以打开一个新的套接字来连接聊天服务,就像这样

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

这还不是一个完整的woriking客户端,但可以获取cookie,也可以登录聊天服务。我不是一个完整的ruby程序员,但已经注意到它很容易使用,所以希望这对mate有所帮助。

我正在做的事情,即将完成

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=
cookies,然后您现在可以打开一个新的套接字来连接聊天服务,就像这样

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
这还不是一个完整的woriking客户端,但可以获得cookie,也可以登录聊天服务,我不是一个完整的ruby程序员,但已经注意到它非常容易使用,所以希望这对mate有所帮助