0

我将omniauth保存在auth变量中,如下所示

auth = request.env["omniauth.auth"]  

当我如下检查时

puts auth.inspect  

它给了我

#<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash secret="ouAWj4Hvb9qwKiDDd66ewI8Hq8pDHj8dtfgdlmvdeJDSxY8" token="136631281-Ruduz2BesDwNwcBlwCaV90H358LCA0rCfLonMCE9"> extra=#<OmniAuth::AuthHash access_token=#<OAuth::AccessToken:0x00000003f77968 @token="136631281-Ruduz2BesDwNwcBlwChghaV90H358LCA0rCfLonMCE9", @secret="ouAWj4Hvb9qwKiDDd66ewgdrfgI8Hq8pDHj8lmvdeJDSxY8", @consumer=#<OAuth::Consumer:0x00000003fdf0cb18 @key="UN8w8rgfdDodjpLVgbWFvzCw", @secret="P2MbbeW4LiIyuuSc5gcQ26hcKzQJEyfBgfdyY5g39p2bo0", @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=>"https://api.twitter.com"}, @http=#<Net::HTTP api.twitter.com:443 open=false>, @http_method=:post, @uri=#<URI::HTTPS:0x00000003f76cc0 URL:https://api.twitter.com>>, @params={:oauth_token=>"136631281-Ruduz2BesDwNwcgrBlwCaV90H358LCA0rCfLonMCE9", "oauth_token"=>"136631281-Ruduz2BesDwNwcBlgrfwCaV90H358LCA0rCfLonMCE9", :oauth_token_secret=>"ouAWj4Hvb9qwKiDDd66ewI8grHq8pDHj8lmvdeJDSxY8", "oauth_token_secret"=>"ouAWj4Hvb9qwKiDDd66ewI8Hq8pDHj8lmvdeJDSxY8", :user_id=>"136631281", "user_id"=>"136631281", :screen_name=>"sanyagrfks", "screen_name"=>"sangryamrocks"}, @response=#<Net::HTTPClientError 429 Too Many Requests readbody=true>> raw_info=#<OmniAuth::AuthHash errors=[#<OmniAuth::AuthHash code=88 message="Rate limit exceeded">]>> info=#<OmniAuth::AuthHash::InfoHash description=nil image=nil location=nil name=nil nickname=nil urls=#<OmniAuth::AuthHash Twitter="https://twitter.com/" Website=nil>> provider="twitter" uid="136631281">

知道我正在访问提供者的价值 puts auth['provider']。我想在 auth 中读取 @params 中的值,并想访问 value :oauth_token,我怎样才能得到它?

4

2 回答 2

0

您可以从凭证哈希中获取令牌和秘密。只需按照此代码获取令牌和秘密

@token = auth["凭证"]["token"]

@secret = auth["凭证"]["secret"]

于 2013-04-22T07:59:07.080 回答
0

即使我遇到了这个问题,如果你想访问密钥,那么你可以像访问它一样访问它

env["omniauth.auth"]["extra"]["access_token"].consumer.key
                  or 
env["omniauth.auth"]["extra"]["access_token"].secret 

访问@secret

于 2013-09-26T10:20:37.420 回答