从哈希中获取值

时间:2012-10-13 12:46:44

标签: ruby jruby trinidad-gem

我正在使用gem twitter_oauth。我输入了令牌,我得到了access_token。现在我想访问此哈希中的一些信息,但由于某些原因它不会让我。我能做的最好的就是检查它:

access_token.inspect #=>
#<OAuth::AccessToken:0x72ca83b2 @params={:oauth_token=>"token (filtered of course)", "oauth_token"=>"token", :oauth_token_secret=>"secret", "oauth_token_secret"=>"secret", :user_id=>"id", "user_id"=>"id", :screen_name=>"Imnotanerd", "screen_name"=>"Imnotanerd"}, @response=#<Net::HTTPOK 200 OK readbody=true>, @consumer=#<OAuth::Consumer:0x6bb7645d @http_method=:post, @options={:signature_method=>"HMAC-SHA1", :request_token_path=>"/oauth/request_token", :authorize_path=>"/oauth/authenticate", :access_token_path=>"/oauth/access_token", :proxy=>nil, :scheme=>:header, :http_method=>:post, :oauth_version=>"1.0", :site=>"http://api.twitter.com", :request_endpoint=>nil}, @secret="secret", @http=#<Net::HTTP api.twitter.com:80 open=false>, @uri=#<URI::HTTP:0x384bc24e URL:http://api.twitter.com>, @key="key">, @token="token", @secret="secret">

我试图像这样访问值:

access_token[params]["user_id"] #gave up on this due to me reasoning that it's confusing params with the routing variable, params
access_token["params"]["user_id"]
access_token["consumer"]["secret"]

所有这些都导致内部服务器错误。报告错误时没有提供其他信息。

我正在使用JRuby 1.7 RC2和最新的Trinidad Web服务器。我也在WEBrick中尝试了这个,并出现同样的错误。

1 个答案:

答案 0 :(得分:0)

由于已经有好几个月,我只是添加@ ionut-hulub上面回答的官方回答,所以这个已经回答的问题停止显示,没有回答。

access_token.params[:user_id]
相关问题